-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgettimeofday-dur.c
36 lines (30 loc) · 1.07 KB
/
gettimeofday-dur.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char** argv) {
struct timespec t_start_total, t_end_total;
volatile struct timespec timestamp;
int num_of_iterations, i, res;
double avg_gtof_call_duration_usecs;
num_of_iterations = 10000;
res = clock_gettime(CLOCK_MONOTONIC, &t_start_total );
if( res != 0 ) {
fprintf(stderr, "error: failed at clock_gettime %d\n", __LINE__);
return 1;
}
for(i=0; i<num_of_iterations; ++i) {
res = clock_gettime(CLOCK_MONOTONIC, ×tamp );
if( res != 0 ) {
fprintf(stderr, "error: failed at clock_gettime %d\n", __LINE__);
return 1;
}
}
res = clock_gettime(CLOCK_MONOTONIC, &t_end_total );
if( res != 0 ) {
fprintf(stderr, "error: failed at clock_gettime %d\n", __LINE__);
return 1;
}
avg_gtof_call_duration_usecs = (t_end_total.tv_sec - t_start_total.tv_sec)*1000000.0 + (t_end_total.tv_nsec - t_start_total.tv_nsec)/1000.0;
avg_gtof_call_duration_usecs = avg_gtof_call_duration_usecs/num_of_iterations;
printf("average clock_gettime duration=%lf usecs\n", avg_gtof_call_duration_usecs);
}