forked from lingtikong/dump2phonon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.cpp
71 lines (58 loc) · 1023 Bytes
/
timer.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "timer.h"
Timer::Timer()
{
flag = 0;
start();
return;
}
void Timer::start()
{
t0 = clock();
time(&tbeg); tprev = tnow = tbeg;
flag |= 1;
return;
}
void Timer::stop()
{
if ( flag&1 ) {
t2 = clock();
time(&tnow); tprev = tnow;
flag |= 2;
}
return;
}
void Timer::print()
{
if ( (flag&3) != 3) return;
cpu_time_used = ((double) (t2 - t0)) / CLOCKS_PER_SEC;
printf("Total CPU time used: %g seconds; walltime: %g seconds.\n", cpu_time_used, difftime(tnow,tbeg));
return;
}
double Timer::cpu_time()
{
if ( (flag&3) != 3) return 0.;
else return ((double) (t2 - t0)) / CLOCKS_PER_SEC;
}
double Timer::wall_time()
{
if ( (flag&3) != 3) return 0.;
else return difftime(tnow,tbeg);
}
double Timer::up2now()
{
if ( (flag&1) != 1) return 0.;
else {
time(&tnow);
return difftime(tnow, tbeg);
}
}
double Timer::sincelast()
{
if ( (flag&1) != 1) return 0.;
else {
time(&tnow);
double tinv = difftime(tnow, tprev);
tprev = tnow;
return tinv;
}
}