Add Apache License version 2.0.
[pbc.git] / misc / get_time.c
blob8932364bcf7794ef068d266c8099e06b13c42ec0
1 #include <sys/time.h>
2 #include <time.h>
4 double pbc_get_time(void) {
5 static struct timeval last_tv, tv;
6 static int first = 1;
7 static double res = 0;
9 if (first) {
10 gettimeofday(&last_tv, NULL);
11 first = 0;
12 return 0;
13 } else {
14 gettimeofday(&tv, NULL);
15 res += tv.tv_sec - last_tv.tv_sec;
16 res += (tv.tv_usec - last_tv.tv_usec) / 1000000.0;
17 last_tv = tv;
19 return res;