-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathtiming.h
67 lines (52 loc) · 1.26 KB
/
timing.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
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef _TIMING_H
#define _TIMING_H
class Timing {
private:
BOOL pentClk;
double pentClkRes;
union {
DWORD tickStart;
LARGE_INTEGER clkStart;
};
public:
Timing(void) {
LARGE_INTEGER pentClkFreq;
pentClk = QueryPerformanceFrequency(&pentClkFreq);
//pentClk = 0;
pentClkRes = 1.0f / (double) pentClkFreq.QuadPart;
}
void start(void) {
if (pentClk) {
startQueryPerformanceCounter(); // use the Pentium internal clock
//startAsmGetPentiumCounter();
} else {
startGetTickCount(); // use the old bad resolution timer
}
}
// returns time passed in seconds
double stop(void) {
double time;
if (pentClk) {
time = stopQueryPerformanceCounter();
//time = stopAsmGetPentiumCounter();
} else {
time = stopGetTickCount();
}
return time;
}
void startQueryPerformanceCounter(void) {
QueryPerformanceCounter(&clkStart);
}
double stopQueryPerformanceCounter(void) {
LARGE_INTEGER clkStop;
QueryPerformanceCounter(&clkStop);
return (clkStop.QuadPart - clkStart.QuadPart) * pentClkRes;
}
void startGetTickCount(void) {
tickStart = GetTickCount();
}
double stopGetTickCount(void) {
return ((double)(GetTickCount() - tickStart)) * 0.001;
}
};
#endif