aboutsummaryrefslogtreecommitdiff
path: root/tools/timerun.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-07-03 15:05:10 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-07-03 15:05:10 +0200
commit4a16da26dacdb37b9ef8d3d11e10ecb94b0cf396 (patch)
tree64723639df2a44c94deb26276c5793101d3b6c41 /tools/timerun.h
parent3c9efb490ccbe1b0d7768d77fcdcac012c00e8c6 (diff)
downloadnissy-core-4a16da26dacdb37b9ef8d3d11e10ecb94b0cf396.tar.gz
nissy-core-4a16da26dacdb37b9ef8d3d11e10ecb94b0cf396.zip
renamed benchmarks to tools
Diffstat (limited to 'tools/timerun.h')
-rw-r--r--tools/timerun.h39
1 files changed, 39 insertions, 0 deletions
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 @@
1#include <stdbool.h>
2#include <inttypes.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <time.h>
6
7double
8timerun(void (*run)(void), char *name)
9{
10 struct timespec start, end;
11 double tdiff, tdsec, tdnano;
12
13 printf("\n");
14 fflush(stdout);
15
16 if (run == NULL) {
17 printf("> %s: nothing to run!\n", name);
18 fflush(stdout);
19 return -1.0;
20 }
21
22 printf("Running tool: %s\n", name);
23 printf("==========\n");
24 fflush(stdout);
25
26 clock_gettime(CLOCK_MONOTONIC, &start);
27 run();
28 clock_gettime(CLOCK_MONOTONIC, &end);
29
30 tdsec = end.tv_sec - start.tv_sec;
31 tdnano = end.tv_nsec - start.tv_nsec;
32 tdiff = tdsec + 1e-9 * tdnano;
33
34 printf("==========\n");
35 printf("\nTotal time: %.4fs\n", tdiff);
36 fflush(stdout);
37
38 return tdiff;
39}

Generated with cgit - Back to sebastiano.tronto.net