diff options
author | Birte Kristina Friesel <birte.friesel@uos.de> | 2024-02-22 08:08:08 +0100 |
---|---|---|
committer | Birte Kristina Friesel <birte.friesel@uos.de> | 2024-02-22 08:08:08 +0100 |
commit | 0f65437a68a26b906ab0da02d9f0ec4b177650fc (patch) | |
tree | c263aa41fa2b400762d205b250f82b1b44ce1a26 /Microbenchmarks/STREAM/support/timer.h | |
parent | a1746b5e3b78b35ea94a65979f9a0ba41dd1eed4 (diff) |
STREAM: Use nano- rather than microsecond precision internally
Diffstat (limited to 'Microbenchmarks/STREAM/support/timer.h')
-rw-r--r-- | Microbenchmarks/STREAM/support/timer.h | 24 |
1 files changed, 11 insertions, 13 deletions
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 <sys/time.h>
+#include <time.h>
-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)); }
|