rcx

miscellaneous C library
git clone git://git.rr3.xyz/rcx
Log | Files | Refs | README | LICENSE

bench.h (623B)


      1 #pragma once
      2 
      3 #include "def.h"
      4 
      5 /*
      6 Usage:
      7 	void my_benchmark(u64 N) {
      8 		<initialization (not timed)>
      9 		r_bench_start();
     10 		for (u64 i = 0; i < N; i++) {
     11 			<code to benchmark>
     12 		}
     13 		r_bench_stop();
     14 		<cleanup (not timed)>
     15 	}
     16 	int main(void) {
     17 		r_bench(my_benchmark, 3000);
     18 	}
     19 Note that <code to benchmark> can contain calls to r_bench_stop and
     20 r_bench_start to pause and restart timing.
     21 */
     22 
     23 #define r_bench(fn, goalms, ...) \
     24 	r_bench_(fn, goalms, VA_DEFAULT(,##__VA_ARGS__, #fn), VA_DROP1(__VA_ARGS__, ""))
     25 
     26 void r_bench_(void (*fn)(u64 N), u32 goalms, char *name, ...);
     27 void r_bench_start(void);
     28 void r_bench_stop(void);