refactor Benchmark related macros

This commit is contained in:
c9s 2014-05-22 16:59:40 +08:00
parent ba270b5948
commit 5ada611182
3 changed files with 23 additions and 21 deletions

View file

@ -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 */

View file

@ -447,3 +447,5 @@
1400748288,13317009.48 1400748288,13317009.48
1400748727,12973679.22 1400748727,12973679.22
1400748826,12902583.84 1400748826,12902583.84
1400748965,13584323.91
1400749175,13518288.33

1 1400242718 5649455.80
447 1400748288 13317009.48
448 1400748727 12973679.22
449 1400748826 12902583.84
450 1400748965 13584323.91
451 1400749175 13518288.33

View file

@ -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