-
Notifications
You must be signed in to change notification settings - Fork 3
/
util.c
26 lines (22 loc) · 596 Bytes
/
util.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
#include <sys/time.h>
#include <stdio.h>
#include "util.h"
struct timeval tv;
double firsttic = 0;
double lasttic = 0;
void tic_reset() {
gettimeofday(&tv, NULL);
firsttic = (double)tv.tv_sec + 1.0e-6 * (double)tv.tv_usec;
lasttic = firsttic;
}
double tic_total() {
gettimeofday(&tv, NULL);
lasttic = (double)tv.tv_sec + 1.0e-6 * (double)tv.tv_usec;
return lasttic - firsttic;
}
double tic_sincelast() {
gettimeofday(&tv, NULL);
double rtnval = ((double)tv.tv_sec + 1.0e-6 * (double)tv.tv_usec) - lasttic;
lasttic = (double)tv.tv_sec + 1.0e-6 * (double)tv.tv_usec;
return rtnval;
}