| 31 | } |
| 32 | |
| 33 | void run_benchmark(char *name, void (*benchmark)(void*), void (*setup)(void*), void (*teardown)(void*), void* data, int count, int iter) { |
| 34 | int i; |
| 35 | double min = HUGE_VAL; |
| 36 | double sum = 0.0; |
| 37 | double max = 0.0; |
| 38 | for (i = 0; i < count; i++) { |
| 39 | double begin, total; |
| 40 | if (setup != NULL) { |
| 41 | setup(data); |
| 42 | } |
| 43 | begin = gettimedouble(); |
| 44 | benchmark(data); |
| 45 | total = gettimedouble() - begin; |
| 46 | if (teardown != NULL) { |
| 47 | teardown(data); |
| 48 | } |
| 49 | if (total < min) { |
| 50 | min = total; |
| 51 | } |
| 52 | if (total > max) { |
| 53 | max = total; |
| 54 | } |
| 55 | sum += total; |
| 56 | } |
| 57 | printf("%s: min ", name); |
| 58 | print_number(min * 1000000.0 / iter); |
| 59 | printf("us / avg "); |
| 60 | print_number((sum / count) * 1000000.0 / iter); |
| 61 | printf("us / max "); |
| 62 | print_number(max * 1000000.0 / iter); |
| 63 | printf("us\n"); |
| 64 | } |
| 65 | |
| 66 | #endif |
no test coverage detected