-
Notifications
You must be signed in to change notification settings - Fork 6
/
STimer.cc
54 lines (41 loc) · 929 Bytes
/
STimer.cc
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
54
#ifndef INCLUDE_STIMER
#define INCLUDE_STIMER
class STimer {
public:
STimer();
~STimer();
void Start(void);
void Stop(void);
double Elapsed(void);
void Clear(void);
int timeron;
struct timeval tuse, tstart, timer;
};
STimer::STimer(void) {
timeron = false;
timerclear(&timer);
timeron = 0;
}
STimer::~STimer() {
}
void STimer::Start() {
assert(!timeron);
assert( gettimeofday( &(tstart), (struct timezone *)NULL ) == 0 );
timeron = 1;
}
void STimer::Stop(void) {
assert( timeron );
struct timeval dt;
assert( gettimeofday( &(tuse), (struct timezone *)NULL ) == 0 );
timersub(&(tuse), &(tstart), &dt);
timeradd(&dt, &(timer), &(timer));
timeron = 0;
}
void STimer::Clear(void) {
assert(!timeron);
timerclear(&(timer));
}
double STimer::Elapsed(void) {
return timer.tv_sec + 1e-6*timer.tv_usec;
}
#endif // INCLUDE_STIMER