-
Notifications
You must be signed in to change notification settings - Fork 37
/
utilities.h
51 lines (43 loc) · 965 Bytes
/
utilities.h
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <sys/time.h>
////////////////////////////////////////////////////////////////////////////////
// MyTimer
////////////////////////////////////////////////////////////////////////////////
// little helper class to time stuff
// this should be in a utilities header file
class MyTimer
{
public:
MyTimer()
{
}
void Start()
{
gettimeofday(&tv1, NULL);
}
double Stop()
{
gettimeofday(&tv2, NULL);
int sec = tv2.tv_sec - tv1.tv_sec;
int usec = tv2.tv_usec - tv1.tv_usec;
if (usec < 0)
{
sec--;
usec = 1000000 + usec;
}
return (double)sec + (double)usec / 1000000.0;
}
void Print(const char *label)
{
int sec = tv2.tv_sec - tv1.tv_sec;
int usec = tv2.tv_usec - tv1.tv_usec;
if (usec < 0)
{
sec--;
usec = 1000000 + usec;
}
printf("%s took %d sec %d usec\n", label, sec, usec);
}
private:
struct timeval tv1, tv2;
};