benchmark function improvements
This commit is contained in:
parent
7f97440c72
commit
c9fe373d91
3 changed files with 10 additions and 8 deletions
|
@ -59,6 +59,11 @@ void bench_print_summary(bench *b) {
|
||||||
printf("%.2f i/sec\n", bench_iteration_speed(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, ...) {
|
void bench_append_csv(char *filename, int countOfB, ...) {
|
||||||
FILE *fp = fopen(filename, "a+");
|
FILE *fp = fopen(filename, "a+");
|
||||||
if(!fp) {
|
if(!fp) {
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
#define SEC_IN_MIN 60
|
#define SEC_IN_MIN 60
|
||||||
#define NUL '\0'
|
#define NUL '\0'
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
long N; // N for each run
|
long N; // N for each run
|
||||||
long R; // runs
|
long R; // runs
|
||||||
|
@ -41,6 +40,7 @@ void bench_append_csv(char *filename, int countOfB, ...);
|
||||||
|
|
||||||
#define BENCHMARK(B) \
|
#define BENCHMARK(B) \
|
||||||
bench B; B.N = 5000000; B.R = 3; \
|
bench B; B.N = 5000000; B.R = 3; \
|
||||||
|
printf("Benchmarking " #B "...\n"); \
|
||||||
bench_start(&B); \
|
bench_start(&B); \
|
||||||
for (int _r = 0; _r < B.R ; _r++ ) { \
|
for (int _r = 0; _r < B.R ; _r++ ) { \
|
||||||
for (int _i = 0; _i < B.N ; _i++ ) {
|
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_SUMMARY(B) bench_print_summary(&B);
|
||||||
|
|
||||||
#define BENCHMARK_RECORD_CSV(B,filename) \
|
#define BENCHMARK_RECORD_CSV(filename, countOfB, ...) \
|
||||||
FILE *fp = fopen(filename, "a+"); \
|
bench_append_csv(filename, countOfB, __VA_ARGS__)
|
||||||
fprintf(fp, "%ld,%.2f\n", unixtime(), (B.N * B.R) / (B.end - B.start)); \
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* !BENCH_H */
|
#endif /* !BENCH_H */
|
||||||
|
|
|
@ -717,13 +717,12 @@ r3_tree_insert_path(n, "/garply/grault/corge", NULL);
|
||||||
ck_assert_int_eq( *((int*) m->data), 999 );
|
ck_assert_int_eq( *((int*) m->data), 999 );
|
||||||
|
|
||||||
|
|
||||||
printf("Benchmarking...\n");
|
|
||||||
BENCHMARK(string_dispatch)
|
BENCHMARK(string_dispatch)
|
||||||
r3_tree_matchl(n , "/qux/bar/corge", strlen("/qux/bar/corge"), NULL);
|
r3_tree_matchl(n , "/qux/bar/corge", strlen("/qux/bar/corge"), NULL);
|
||||||
END_BENCHMARK(string_dispatch)
|
END_BENCHMARK(string_dispatch)
|
||||||
|
|
||||||
BENCHMARK_SUMMARY(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
|
END_TEST
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue