5 static struct timespec start_time;
7 void start_benchmark_timer()
9 if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time) == -1) {
10 perror("clock_gettime()");
15 static double timediff(const struct timespec* a, const struct timespec* b)
17 return (double)(b->tv_sec - a->tv_sec) +
18 (double)(b->tv_nsec - a->tv_nsec) * 1e-9;
21 double stop_benchmark_timer()
24 if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &now) == -1) {
25 perror("clock_gettime()");
29 return timediff(&start_time, &now);