From 7e44ee01f45b83214f54af1e48d9ebf635101468 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 22 May 2014 16:59:40 +0800 Subject: [PATCH] refactor Benchmark related macros Conflicts: tests/bench_str.csv --- tests/bench.h | 32 ++++++++++++++++++-------------- tests/check_tree.c | 10 +++------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/bench.h b/tests/bench.h index 27dd975..c4f691e 100644 --- a/tests/bench.h +++ b/tests/bench.h @@ -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 */ diff --git a/tests/check_tree.c b/tests/check_tree.c index 72af3e1..88ebba1 100644 --- a/tests/check_tree.c +++ b/tests/check_tree.c @@ -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