blob: 0a4d6a16de3c50b892234d9bf83d47d0750b8295 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#pragma once
#include <time.h>
typedef struct Timer {
struct timespec startTime[7];
struct timespec stopTime[7];
uint64_t nanoseconds[7];
} Timer;
void start(Timer *timer, int i, int rep) {
if(rep == 0) {
timer->nanoseconds[i] = 0;
}
clock_gettime(CLOCK_MONOTONIC, &timer->startTime[i]);
}
void stop(Timer *timer, int i) {
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);
}
|