@@ -93,6 +93,11 @@ void assume_duration(double expected, double actual, double unit) {
9393
9494// Marks a test case as timeout with a specified time and prints it to stderr.
9595void fossil_test_benchmark (char * duration_type , double expected , double actual ) {
96+ if (duration_type == NULL ) {
97+ printf ("Error: duration_type is NULL\n" );
98+ return ;
99+ }
100+
96101 if (strcmp (duration_type , "minutes" ) == 0 ) {
97102 assume_duration (expected , actual , 60.0 );
98103 } else if (strcmp (duration_type , "seconds" ) == 0 ) {
@@ -119,6 +124,16 @@ void fossil_test_benchmark(char* duration_type, double expected, double actual)
119124} // end of func
120125
121126void fossil_benchmark_init (fossil_benchmark_t * benchmark , const char * name ) {
127+ if (benchmark == NULL ) {
128+ printf ("Error: benchmark is NULL\n" );
129+ return ;
130+ }
131+
132+ if (name == NULL ) {
133+ printf ("Error: name is NULL\n" );
134+ return ;
135+ }
136+
122137 benchmark -> name = name ;
123138 benchmark -> num_samples = 0 ;
124139 benchmark -> total_duration = 0.0 ;
@@ -128,13 +143,23 @@ void fossil_benchmark_init(fossil_benchmark_t* benchmark, const char* name) {
128143}
129144
130145void fossil_benchmark_start (fossil_benchmark_t * benchmark ) {
146+ if (benchmark == NULL ) {
147+ printf ("Error: benchmark is NULL\n" );
148+ return ;
149+ }
150+
131151 if (!benchmark -> running ) {
132152 benchmark -> start_time = clock ();
133153 benchmark -> running = 1 ;
134154 }
135155}
136156
137157void fossil_benchmark_stop (fossil_benchmark_t * benchmark ) {
158+ if (benchmark == NULL ) {
159+ printf ("Error: benchmark is NULL\n" );
160+ return ;
161+ }
162+
138163 if (benchmark -> running ) {
139164 benchmark -> end_time = clock ();
140165 double elapsed = ((double )(benchmark -> end_time - benchmark -> start_time )) / CLOCKS_PER_SEC ;
@@ -151,29 +176,53 @@ void fossil_benchmark_stop(fossil_benchmark_t* benchmark) {
151176}
152177
153178double fossil_benchmark_elapsed_seconds (const fossil_benchmark_t * benchmark ) {
179+ if (benchmark == NULL ) {
180+ printf ("Error: benchmark is NULL\n" );
181+ return 0.0 ;
182+ }
154183 return benchmark -> total_duration ;
155184}
156185
157186double fossil_benchmark_min_time (const fossil_benchmark_t * benchmark ) {
187+ if (benchmark == NULL ) {
188+ printf ("Error: benchmark is NULL\n" );
189+ return 0.0 ;
190+ }
158191 return benchmark -> min_duration ;
159192}
160193
161194double fossil_benchmark_max_time (const fossil_benchmark_t * benchmark ) {
195+ if (benchmark == NULL ) {
196+ printf ("Error: benchmark is NULL\n" );
197+ return 0.0 ;
198+ }
162199 return benchmark -> max_duration ;
163200}
164201
165202double fossil_benchmark_avg_time (const fossil_benchmark_t * benchmark ) {
203+ if (benchmark == NULL ) {
204+ printf ("Error: benchmark is NULL\n" );
205+ return 0.0 ;
206+ }
166207 return benchmark -> num_samples > 0 ? benchmark -> total_duration / benchmark -> num_samples : 0.0 ;
167208}
168209
169210void fossil_benchmark_reset (fossil_benchmark_t * benchmark ) {
211+ if (benchmark == NULL ) {
212+ printf ("Error: benchmark is NULL\n" );
213+ return ;
214+ }
170215 benchmark -> num_samples = 0 ;
171216 benchmark -> total_duration = 0.0 ;
172217 benchmark -> min_duration = DBL_MAX ;
173218 benchmark -> max_duration = 0.0 ;
174219}
175220
176221void fossil_benchmark_report (const fossil_benchmark_t * benchmark ) {
222+ if (benchmark == NULL ) {
223+ printf ("Error: benchmark is NULL\n" );
224+ return ;
225+ }
177226 printf ("\033[1;36mBenchmark : %s\n" , benchmark -> name );
178227 printf ("\033[1;32mTotal Time: %.6f seconds\n" , fossil_benchmark_elapsed_seconds (benchmark ));
179228 printf ("\033[1;32mMin Time : %.6f seconds\n" , fossil_benchmark_min_time (benchmark ));
@@ -182,10 +231,25 @@ void fossil_benchmark_report(const fossil_benchmark_t* benchmark) {
182231}
183232
184233void fossil_scoped_benchmark_init (scoped_benchmark_t * scoped_benchmark , fossil_benchmark_t * benchmark ) {
234+ if (scoped_benchmark == NULL ) {
235+ printf ("Error: scoped_benchmark is NULL\n" );
236+ return ;
237+ }
238+
239+ if (benchmark == NULL ) {
240+ printf ("Error: benchmark is NULL\n" );
241+ return ;
242+ }
243+
185244 scoped_benchmark -> benchmark = benchmark ;
186245 fossil_benchmark_start (scoped_benchmark -> benchmark );
187246}
188247
189248void fossil_scoped_benchmark_destroy (scoped_benchmark_t * scoped_benchmark ) {
249+ if (scoped_benchmark == NULL ) {
250+ printf ("Error: scoped_benchmark is NULL\n" );
251+ return ;
252+ }
253+
190254 fossil_benchmark_stop (scoped_benchmark -> benchmark );
191255}
0 commit comments