Add bench_append_csv to combine multiple benchmark result in one entry

This commit is contained in:
c9s 2014-05-22 20:48:01 +08:00
parent 3879316e08
commit 7f97440c72
3 changed files with 34 additions and 3 deletions

View file

@ -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) {
@ -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);
}

View file

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

View file

@ -443,3 +443,4 @@
1400668574,13632260.72
1400681414,10832905.89
1400685490,13185955.87
1400762875,10472029.42

1 1400242718 5649455.80
443 1400668574 13632260.72
444 1400681414 10832905.89
445 1400685490 13185955.87
446 1400762875 10472029.42