diff --git a/tests/bench.c b/tests/bench.c index c3ef66b5..84344f0a 100644 --- a/tests/bench.c +++ b/tests/bench.c @@ -9,8 +9,9 @@ #include #include #include +#include /* 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) { @@ -35,7 +36,6 @@ double microtime() { return 0; } - void bench_start(bench *b) { b->start = microtime(); } @@ -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); +} + + + diff --git a/tests/bench.h b/tests/bench.h index 0d4c8984..dbae90bf 100644 --- a/tests/bench.h +++ b/tests/bench.h @@ -23,7 +23,7 @@ typedef struct { double end; } bench; -long unixtime(); +unsigned long unixtime(); double microtime(); @@ -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); \ @@ -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 */ diff --git a/tests/bench_str.csv b/tests/bench_str.csv index a10d1c5c..79871fd0 100644 --- a/tests/bench_str.csv +++ b/tests/bench_str.csv @@ -443,3 +443,4 @@ 1400668574,13632260.72 1400681414,10832905.89 1400685490,13185955.87 +1400762875,10472029.42