From 4a16da26dacdb37b9ef8d3d11e10ecb94b0cf396 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Wed, 3 Jul 2024 15:05:10 +0200 Subject: renamed benchmarks to tools --- tools/timerun.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tools/timerun.h (limited to 'tools/timerun.h') diff --git a/tools/timerun.h b/tools/timerun.h new file mode 100644 index 0000000..dabfde0 --- /dev/null +++ b/tools/timerun.h @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include + +double +timerun(void (*run)(void), char *name) +{ + struct timespec start, end; + double tdiff, tdsec, tdnano; + + printf("\n"); + fflush(stdout); + + if (run == NULL) { + printf("> %s: nothing to run!\n", name); + fflush(stdout); + return -1.0; + } + + printf("Running tool: %s\n", name); + printf("==========\n"); + fflush(stdout); + + clock_gettime(CLOCK_MONOTONIC, &start); + run(); + clock_gettime(CLOCK_MONOTONIC, &end); + + tdsec = end.tv_sec - start.tv_sec; + tdnano = end.tv_nsec - start.tv_nsec; + tdiff = tdsec + 1e-9 * tdnano; + + printf("==========\n"); + printf("\nTotal time: %.4fs\n", tdiff); + fflush(stdout); + + return tdiff; +} -- cgit v1.3