commit cc64e10596e638abf7689130ebee5ae28455f8f4
parent 24255ed919b2a40830954ef47df6901e566f46aa
Author: Laslo Hunhold <dev@frign.de>
Date: Tue, 14 Dec 2021 13:39:36 +0100
Change return-type of time_diff to double
This makes it a bit easier to work with, more readable and lowers the
risk of an (even 64 unsigned bit integer!) overflow.
Signed-off-by: Laslo Hunhold <dev@frign.de>
Diffstat:
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/test/grapheme-performance.c b/test/grapheme-performance.c
@@ -11,11 +11,11 @@
#define LEN(x) (sizeof(x) / sizeof(*(x)))
#define NUM_ITERATIONS 10000
-static int64_t
+static double
time_diff(struct timespec *a, struct timespec *b)
{
- return ((b->tv_sec * 1000000000) + b->tv_nsec) -
- ((a->tv_sec * 1000000000) + a->tv_nsec);
+ return (double)(b->tv_sec - a->tv_sec) +
+ (double)(b->tv_nsec - a->tv_nsec) * 1E-9;
}
int
@@ -58,8 +58,9 @@ main(void)
}
}
clock_gettime(CLOCK_MONOTONIC, &end);
- cp_per_sec = ((double)NUM_ITERATIONS * (double)bufsiz) /
- (time_diff(&start, &end) / 1000000000);
+
+ cp_per_sec = (double)(NUM_ITERATIONS * bufsiz) /
+ time_diff(&start, &end);
printf(" %.2e CP/s\n", cp_per_sec);