-
Notifications
You must be signed in to change notification settings - Fork 4
/
StopWatch.h
53 lines (42 loc) · 796 Bytes
/
StopWatch.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
51
52
53
#ifndef __STOP_WATCH_H
#define __STOP_WATCH_H
#if defined(_WIN32) || defined(_WIN64)
#include <time.h>
#include <windows.h>
typedef unsigned __int64 uint64_t;
struct timezone {
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
};
int gettimeofday(struct timeval *tv, struct timezone *tz);
#else
#include <stdint.h>
#include <sys/time.h>
#endif
class StopWatch
{
public:
StopWatch()
{
reset();
}
void reset()
{
elapsed.tv_sec = 0;
elapsed.tv_usec = 0;
}
uint64_t elapsed_usec();
void elapsed_timeval(struct timeval *res)
{
*res = elapsed;
}
void run()
{
gettimeofday(&start, NULL);
}
void stop();
protected:
struct timeval elapsed;
struct timeval start;
};
#endif // __STOP_WATCH_H