-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHighClock.h
70 lines (57 loc) · 1.27 KB
/
HighClock.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
67
68
69
70
#include <windows.h>
LARGE_INTEGER TimerStart();
LARGE_INTEGER TimerEnd();
LARGE_INTEGER GetTime(LARGE_INTEGER start,LARGE_INTEGER end);
LARGE_INTEGER TimerStart()
{
LARGE_INTEGER start;
QueryPerformanceCounter(&start);
return start;
}
LARGE_INTEGER TimerEnd()
{
LARGE_INTEGER end;
QueryPerformanceCounter(&end);
return end;
}
LARGE_INTEGER GetTime(LARGE_INTEGER start,LARGE_INTEGER end)
{
LARGE_INTEGER Freq;
QueryPerformanceFrequency(&Freq);
LARGE_INTEGER use;
use.QuadPart=( end.QuadPart - start.QuadPart)*1000/ Freq.QuadPart;
return use;
}
//! High-resolution clock (In fraction of seconds, as milliseconds)
//单位:秒
class HighClock
{
public:
HighClock()
{
// Setup the high-resolution timer
QueryPerformanceFrequency(&TicksPerSec);
// High-resolution timers, iniitalized timer
QueryPerformanceCounter(&startTime);
// Start off the timer
Start(); Stop();
}
void Stop()
{
QueryPerformanceCounter(&endTime);
}
// In seconds
float GetTime()
{
// Measure the cycle time
cpuTime.QuadPart = endTime.QuadPart - startTime.QuadPart;
return (float)cpuTime.QuadPart / (float)TicksPerSec.QuadPart;
}
void Start()
{
QueryPerformanceCounter(&startTime);
}
private:
LARGE_INTEGER TicksPerSec;
LARGE_INTEGER startTime, endTime, cpuTime;
};