-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.cpp
More file actions
66 lines (59 loc) · 1.61 KB
/
Timer.cpp
File metadata and controls
66 lines (59 loc) · 1.61 KB
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
#include "Timer.hpp"
namespace Core
{
HighresTimer::HighresTimer()
{
#ifndef WCLOCK
m_totalStart = std::chrono::high_resolution_clock::now();
#else
QueryPerformanceFrequency(&m_frequency);
QueryPerformanceCounter(&m_totalStart);
#endif
}
void HighresTimer::Start()
{
#ifndef WCLOCK
m_start = std::chrono::high_resolution_clock::now();
#else
QueryPerformanceCounter(&m_start);
#endif
}
void HighresTimer::Stop()
{
#ifndef WCLOCK
m_end = std::chrono::high_resolution_clock::now();
#else
QueryPerformanceCounter(&m_end);
#endif
}
void HighresTimer::Reset()
{
#ifndef WCLOCK
m_totalStart = std::chrono::high_resolution_clock::now();
#else
QueryPerformanceCounter(&m_totalStart);
#endif
}
std::chrono::microseconds HighresTimer::GetDelta()
{
#ifndef WCLOCK
return std::chrono::duration_cast<std::chrono::microseconds>( m_end - m_start );
#else
double elapsed = ((m_end.QuadPart - m_start.QuadPart)*1E6)/static_cast<double>(m_frequency.QuadPart);
std::chrono::duration<double, std::micro> ms(elapsed);
return std::chrono::duration_cast<std::chrono::microseconds>( ms );
#endif
}
long long HighresTimer::GetTotal()
{
#ifndef WCLOCK
std::chrono::high_resolution_clock::time_point now = std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<std::chrono::milliseconds>( now - m_totalStart ).count();
#else
LARGE_INTEGER now;
QueryPerformanceCounter(&now);
long long elapsed = 1000 * (now.QuadPart - m_totalStart.QuadPart)/m_frequency.QuadPart;
return elapsed;
#endif
}
}