benchmark function improvements

This commit is contained in:
c9s 2014-05-22 21:01:25 +08:00
parent 7f97440c72
commit c9fe373d91
3 changed files with 10 additions and 8 deletions

View file

@ -59,6 +59,11 @@ void bench_print_summary(bench *b) {
printf("%.2f i/sec\n", bench_iteration_speed(b) );
}
/**
* Combine multiple benchmark result into one measure entry.
*
* bench_append_csv("benchmark.csv", 3, &b1, &b2)
*/
void bench_append_csv(char *filename, int countOfB, ...) {
FILE *fp = fopen(filename, "a+");
if(!fp) {

View file

@ -14,7 +14,6 @@
#define SEC_IN_MIN 60
#define NUL '\0'
typedef struct {
long N; // N for each run
long R; // runs
@ -41,6 +40,7 @@ void bench_append_csv(char *filename, int countOfB, ...);
#define BENCHMARK(B) \
bench B; B.N = 5000000; B.R = 3; \
printf("Benchmarking " #B "...\n"); \
bench_start(&B); \
for (int _r = 0; _r < B.R ; _r++ ) { \
for (int _i = 0; _i < B.N ; _i++ ) {
@ -52,10 +52,8 @@ void bench_append_csv(char *filename, int countOfB, ...);
#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);
#define BENCHMARK_RECORD_CSV(filename, countOfB, ...) \
bench_append_csv(filename, countOfB, __VA_ARGS__)
#endif /* !BENCH_H */

View file

@ -717,13 +717,12 @@ r3_tree_insert_path(n, "/garply/grault/corge", NULL);
ck_assert_int_eq( *((int*) m->data), 999 );
printf("Benchmarking...\n");
BENCHMARK(string_dispatch)
r3_tree_matchl(n , "/qux/bar/corge", strlen("/qux/bar/corge"), NULL);
END_BENCHMARK(string_dispatch)
BENCHMARK_SUMMARY(string_dispatch);
BENCHMARK_RECORD_CSV(string_dispatch, "bench_str.csv")
BENCHMARK_RECORD_CSV("bench_str.csv", 1, &string_dispatch);
}
END_TEST