-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtimer.h
69 lines (56 loc) · 1.22 KB
/
timer.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
/*******************************************************************************
* This file is part of AvsVCEh264.
* Contains simple high-resolution Timer class
*
* Copyright (C) 2013 David González García <[email protected]>
*******************************************************************************/
#ifndef TIMER_H
#define TIMER_H
#include <stdlib.h>
#include <windows.h>
class Timer
{
public:
Timer()
{
LARGE_INTEGER frequency;
QueryPerformanceFrequency(&frequency);
mul = 1000000.0 / frequency.QuadPart;
}
~Timer() {}
inline void start()
{
endCount.QuadPart = 0;
QueryPerformanceCounter(&startCount);
}
inline void stop()
{
QueryPerformanceCounter(&endCount);
}
double getElapsedTime()
{
return this->getInSec();
}
double getInSec()
{
return this->getInMicroSec() * 0.000001;
}
double getInMilliSec()
{
return this->getInMicroSec() * 0.001;
}
double getInMicroSec()
{
LARGE_INTEGER end;
if(endCount.QuadPart == 0)
QueryPerformanceCounter(&end);
else
end = endCount;
return end.QuadPart * mul - startCount.QuadPart * mul;
}
private:
double mul;
LARGE_INTEGER startCount;
LARGE_INTEGER endCount;
};
#endif