diff options
Diffstat (limited to 'tools/timerun.h')
| -rw-r--r-- | tools/timerun.h | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/tools/timerun.h b/tools/timerun.h deleted file mode 100644 index 58a8e7a..0000000 --- a/tools/timerun.h +++ /dev/null | |||
| @@ -1,51 +0,0 @@ | |||
| 1 | #include <stdarg.h> | ||
| 2 | #include <stdbool.h> | ||
| 3 | #include <inttypes.h> | ||
| 4 | #include <stdio.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | #include <time.h> | ||
| 7 | |||
| 8 | void | ||
| 9 | log_stderr(const char *str, ...) | ||
| 10 | { | ||
| 11 | va_list args; | ||
| 12 | |||
| 13 | va_start(args, str); | ||
| 14 | vfprintf(stderr, str, args); | ||
| 15 | va_end(args); | ||
| 16 | } | ||
| 17 | |||
| 18 | |||
| 19 | double | ||
| 20 | timerun(void (*run)(void), char *name) | ||
| 21 | { | ||
| 22 | struct timespec start, end; | ||
| 23 | double tdiff, tdsec, tdnano; | ||
| 24 | |||
| 25 | printf("\n"); | ||
| 26 | fflush(stdout); | ||
| 27 | |||
| 28 | if (run == NULL) { | ||
| 29 | printf("> %s: nothing to run!\n", name); | ||
| 30 | fflush(stdout); | ||
| 31 | return -1.0; | ||
| 32 | } | ||
| 33 | |||
| 34 | printf("Running tool: %s\n", name); | ||
| 35 | printf("==========\n"); | ||
| 36 | fflush(stdout); | ||
| 37 | |||
| 38 | clock_gettime(CLOCK_MONOTONIC, &start); | ||
| 39 | run(); | ||
| 40 | clock_gettime(CLOCK_MONOTONIC, &end); | ||
| 41 | |||
| 42 | tdsec = end.tv_sec - start.tv_sec; | ||
| 43 | tdnano = end.tv_nsec - start.tv_nsec; | ||
| 44 | tdiff = tdsec + 1e-9 * tdnano; | ||
| 45 | |||
| 46 | printf("==========\n"); | ||
| 47 | printf("\nTotal time: %.4fs\n", tdiff); | ||
| 48 | fflush(stdout); | ||
| 49 | |||
| 50 | return tdiff; | ||
| 51 | } | ||
