Skip to content

Commit

Permalink
benchmark function improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed May 22, 2014
1 parent 7f97440 commit c9fe373
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 5 additions & 0 deletions tests/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 3 additions & 5 deletions tests/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#define SEC_IN_MIN 60
#define NUL '\0'


typedef struct {
long N; // N for each run
long R; // runs
Expand All @@ -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++ ) {
Expand All @@ -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 */
5 changes: 2 additions & 3 deletions tests/check_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c9fe373

Please sign in to comment.