forked from RPCS3/rpcs3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimer.h
52 lines (41 loc) · 1.1 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
#pragma once
#include <chrono>
class Timer
{
private:
bool m_stopped;
std::chrono::high_resolution_clock::time_point m_start;
std::chrono::high_resolution_clock::time_point m_end;
public:
Timer() : m_stopped(false)
{
}
void Start()
{
m_stopped = false;
m_start = std::chrono::high_resolution_clock::now();
}
void Stop()
{
m_stopped = true;
m_end = std::chrono::high_resolution_clock::now();
}
double GetElapsedTimeInSec() const
{
return double(GetElapsedTimeInMicroSec()) / 1000000.0;
}
double GetElapsedTimeInMilliSec() const
{
return double(GetElapsedTimeInMicroSec()) / 1000.0;
}
u64 GetElapsedTimeInMicroSec() const
{
std::chrono::high_resolution_clock::time_point now = m_stopped ? m_end : std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<std::chrono::microseconds>(now - m_start).count();
}
u64 GetElapsedTimeInNanoSec() const
{
std::chrono::high_resolution_clock::time_point now = m_stopped ? m_end : std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<std::chrono::nanoseconds>(now - m_start).count();
}
};