Skip to content

Commit

Permalink
Add bench_append_csv to combine multiple benchmark result in one entry
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed May 22, 2014
1 parent 3879316 commit 7f97440
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
31 changes: 29 additions & 2 deletions tests/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <stdarg.h> /* va_list, va_start, va_arg, va_end */

long unixtime() {
unsigned long unixtime() {
struct timeval tp;
long sec = 0L;
if (gettimeofday((struct timeval *) &tp, (NUL)) == 0) {
Expand All @@ -35,7 +36,6 @@ double microtime() {
return 0;
}


void bench_start(bench *b) {
b->start = microtime();
}
Expand All @@ -58,3 +58,30 @@ void bench_print_summary(bench *b) {
printf("finished in %lf seconds\n", bench_duration(b) );
printf("%.2f i/sec\n", bench_iteration_speed(b) );
}

void bench_append_csv(char *filename, int countOfB, ...) {
FILE *fp = fopen(filename, "a+");
if(!fp) {
return;
}

unsigned long ts = unixtime();
fprintf(fp, "%ld", ts);


int i;
bench * b;
va_list vl;
va_start(vl,countOfB);
for (i=0 ; i < countOfB ; i++) {
b = va_arg(vl, bench*);
fprintf(fp, ",%.2f", bench_iteration_speed(b) );
}
va_end(vl);

fprintf(fp, "\n");
fclose(fp);
}



5 changes: 4 additions & 1 deletion tests/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef struct {
double end;
} bench;

long unixtime();
unsigned long unixtime();

double microtime();

Expand All @@ -37,6 +37,8 @@ void bench_print_summary(bench *b);

double bench_duration(bench *b);

void bench_append_csv(char *filename, int countOfB, ...);

#define BENCHMARK(B) \
bench B; B.N = 5000000; B.R = 3; \
bench_start(&B); \
Expand All @@ -55,4 +57,5 @@ double bench_duration(bench *b);
fprintf(fp, "%ld,%.2f\n", unixtime(), (B.N * B.R) / (B.end - B.start)); \
fclose(fp);


#endif /* !BENCH_H */
1 change: 1 addition & 0 deletions tests/bench_str.csv
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,4 @@
1400668574,13632260.72
1400681414,10832905.89
1400685490,13185955.87
1400762875,10472029.42

0 comments on commit 7f97440

Please sign in to comment.