refactor Benchmark related macros
Conflicts: tests/bench_str.csv
This commit is contained in:
parent
18b2cf644d
commit
7e44ee01f4
2 changed files with 21 additions and 21 deletions
|
@ -23,20 +23,6 @@ typedef struct {
|
||||||
double end;
|
double end;
|
||||||
} bench;
|
} 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();
|
long unixtime();
|
||||||
|
|
||||||
double microtime();
|
double microtime();
|
||||||
|
@ -49,4 +35,22 @@ double bench_iteration_speed(bench *b);
|
||||||
|
|
||||||
void bench_print_summary(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 */
|
#endif /* !BENCH_H */
|
||||||
|
|
|
@ -720,14 +720,10 @@ r3_tree_insert_path(n, "/garply/grault/corge", NULL);
|
||||||
printf("Benchmarking...\n");
|
printf("Benchmarking...\n");
|
||||||
BENCHMARK(string_dispatch)
|
BENCHMARK(string_dispatch)
|
||||||
r3_tree_matchl(n , "/qux/bar/corge", strlen("/qux/bar/corge"), NULL);
|
r3_tree_matchl(n , "/qux/bar/corge", strlen("/qux/bar/corge"), NULL);
|
||||||
END_BENCHMARK()
|
END_BENCHMARK(string_dispatch)
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
BENCHMARK_SUMMARY(string_dispatch);
|
||||||
|
BENCHMARK_RECORD_CSV(string_dispatch, "bench_str.csv")
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue