From 0f65437a68a26b906ab0da02d9f0ec4b177650fc Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Thu, 22 Feb 2024 08:08:08 +0100 Subject: STREAM: Use nano- rather than microsecond precision internally --- Microbenchmarks/STREAM/support/timer.h | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'Microbenchmarks/STREAM/support') diff --git a/Microbenchmarks/STREAM/support/timer.h b/Microbenchmarks/STREAM/support/timer.h index b53d95f..901baac 100644 --- a/Microbenchmarks/STREAM/support/timer.h +++ b/Microbenchmarks/STREAM/support/timer.h @@ -33,27 +33,25 @@ * */ -#include +#include -typedef struct Timer{ +typedef struct Timer { - struct timeval startTime[7]; - struct timeval stopTime[7]; - double time[7]; + struct timespec startTime[7]; + struct timespec stopTime[7]; + uint64_t nanoseconds[7]; -}Timer; +} Timer; void start(Timer *timer, int i, int rep) { if(rep == 0) { - timer->time[i] = 0.0; + timer->nanoseconds[i] = 0; } - gettimeofday(&timer->startTime[i], NULL); + clock_gettime(CLOCK_MONOTONIC, &timer->startTime[i]); } void stop(Timer *timer, int i) { - gettimeofday(&timer->stopTime[i], NULL); - timer->time[i] += (timer->stopTime[i].tv_sec - timer->startTime[i].tv_sec) * 1000000.0 + - (timer->stopTime[i].tv_usec - timer->startTime[i].tv_usec); + clock_gettime(CLOCK_MONOTONIC, &timer->stopTime[i]); + timer->nanoseconds[i] += (timer->stopTime[i].tv_sec - timer->startTime[i].tv_sec) * 1000000000 + + (timer->stopTime[i].tv_nsec - timer->startTime[i].tv_nsec); } - -void print(Timer *timer, int i, int REP) { printf("Time (ms): %f\t", timer->time[i] / (1000 * REP)); } -- cgit v1.2.3