commit cc64e10596e638abf7689130ebee5ae28455f8f4
Author:     Laslo Hunhold <[email protected]>
AuthorDate: Tue Dec 14 13:39:36 2021 +0100
Commit:     Laslo Hunhold <[email protected]>
CommitDate: Tue Dec 14 13:40:48 2021 +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 <[email protected]>

diff --git a/test/grapheme-performance.c b/test/grapheme-performance.c
index 4ad770f..4269bce 100644
--- 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);
 

Reply via email to