refactor Benchmark related macros
This commit is contained in:
parent
ba270b5948
commit
5ada611182
3 changed files with 23 additions and 21 deletions
|
@ -23,20 +23,6 @@ typedef struct {
|
|||
double end;
|
||||
} bench;
|
||||
|
||||
|
||||
#define BENCHMARK(name) \
|
||||
bench B; B.N = 5000000; B.R = 3; \
|
||||
bench_start(&B); \
|
||||
for (int _r = 0; _r < B.R ; _r++ ) { \
|
||||
for (int _i = 0; _i < B.N ; _i++ ) {
|
||||
|
||||
#define END_BENCHMARK() \
|
||||
} \
|
||||
} \
|
||||
bench_stop(&B);
|
||||
|
||||
|
||||
|
||||
long unixtime();
|
||||
|
||||
double microtime();
|
||||
|
@ -49,4 +35,22 @@ double bench_iteration_speed(bench *b);
|
|||
|
||||
void bench_print_summary(bench *b);
|
||||
|
||||
#define BENCHMARK(B) \
|
||||
bench B; B.N = 5000000; B.R = 3; \
|
||||
bench_start(&B); \
|
||||
for (int _r = 0; _r < B.R ; _r++ ) { \
|
||||
for (int _i = 0; _i < B.N ; _i++ ) {
|
||||
|
||||
#define END_BENCHMARK(B) \
|
||||
} \
|
||||
} \
|
||||
bench_stop(&B);
|
||||
|
||||
#define BENCHMARK_SUMMARY(B) bench_print_summary(&B);
|
||||
|
||||
#define BENCHMARK_RECORD_CSV(B,filename) \
|
||||
FILE *fp = fopen(filename, "a+"); \
|
||||
fprintf(fp, "%ld,%.2f\n", unixtime(), (B.N * B.R) / (B.end - B.start)); \
|
||||
fclose(fp);
|
||||
|
||||
#endif /* !BENCH_H */
|
||||
|
|
|
@ -447,3 +447,5 @@
|
|||
1400748288,13317009.48
|
||||
1400748727,12973679.22
|
||||
1400748826,12902583.84
|
||||
1400748965,13584323.91
|
||||
1400749175,13518288.33
|
||||
|
|
|
|
@ -720,14 +720,10 @@ r3_tree_insert_path(n, "/garply/grault/corge", NULL);
|
|||
printf("Benchmarking...\n");
|
||||
BENCHMARK(string_dispatch)
|
||||
r3_tree_matchl(n , "/qux/bar/corge", strlen("/qux/bar/corge"), NULL);
|
||||
END_BENCHMARK()
|
||||
|
||||
bench_print_summary(&B);
|
||||
|
||||
FILE *fp = fopen("bench_str.csv", "a+");
|
||||
fprintf(fp, "%ld,%.2f\n", unixtime(), (B.N * B.R) / (B.end - B.start));
|
||||
fclose(fp);
|
||||
END_BENCHMARK(string_dispatch)
|
||||
|
||||
BENCHMARK_SUMMARY(string_dispatch);
|
||||
BENCHMARK_RECORD_CSV(string_dispatch, "bench_str.csv")
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
|
Loading…
Reference in a new issue