aboutsummaryrefslogtreecommitdiff
path: root/tools/timerun.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-08-29 15:51:33 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-08-29 15:51:33 +0200
commit7e6c14a2f6e9e9cbac3431f3085c42bbe474d13d (patch)
treee570ec2fd344d7251a89a0c9ec0da94162e62cfc /tools/timerun.h
parentb1fc4886520762dfac016cae612da959078ae67e (diff)
downloadnissy-core-7e6c14a2f6e9e9cbac3431f3085c42bbe474d13d.tar.gz
nissy-core-7e6c14a2f6e9e9cbac3431f3085c42bbe474d13d.zip
Refactor tools to remove duplicate code
Diffstat (limited to 'tools/timerun.h')
-rw-r--r--tools/timerun.h51
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
8void
9log_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
19double
20timerun(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}

Generated with cgit - Back to sebastiano.tronto.net