-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperftimer.cpp
51 lines (40 loc) · 1.17 KB
/
perftimer.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
#include "pch.h"
/*
The perfect timer :) code (C) by E}I{ [email protected]
this part of gpuE}I{soft can be redistributed and modified
in either source or binary form as long as this notice isn't changed or removed.
Code requires x98 MMX CPU and Win32 VC5.0 compatible compiler.
*/
// Timer () will return time passed from previous call in mksec as uint32_t
static LARGE_INTEGER oldtimer,newtimer;
static LARGE_INTEGER kf;
// Prepare data structures for timers, call at least once
void TimerInit(void) {
QueryPerformanceFrequency(&kf);
}
// reset Timer
void Timer(void) {
QueryPerformanceCounter(&oldtimer);
}
// Get timer, no reset
uint32_t GetTimer(void) {
QueryPerformanceCounter(&newtimer);
LARGE_INTEGER diff{};
diff.QuadPart = newtimer.QuadPart - oldtimer.QuadPart;
diff.QuadPart *= 1000000;
diff.QuadPart /= kf.QuadPart;
return diff.LowPart;
}
// Get timer and reset
uint32_t GetTimerR(void) {
uint32_t t = GetTimer();
oldtimer.QuadPart = newtimer.QuadPart;
return t;
}
void TimerTest() {
Timer();
uint32_t stamp1 = GetTimer();
::Sleep(1000);
uint32_t stamp2 = GetTimer();
printf("TimerTest, ticks between Sleep(1000), should be around 1'000'000: %d\n", stamp2 - stamp1);
}