-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTimer.cpp
More file actions
47 lines (37 loc) · 690 Bytes
/
Timer.cpp
File metadata and controls
47 lines (37 loc) · 690 Bytes
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
#include "Timer.h"
using namespace std::chrono;
Timer::Timer()
{
start();
}
void Timer::start()
{
m_StartTime = steady_clock::now();
m_bRunning = true;
}
void Timer::stop()
{
m_EndTime = steady_clock::now();
m_bRunning = false;
}
double Timer::elapsedMilliseconds()
{
return duration_cast<milliseconds>(_elapsed()).count();
}
double Timer::elapsedSeconds()
{
return duration_cast<seconds>(_elapsed()).count();
}
steady_clock::duration Timer::_elapsed() const
{
decltype(m_StartTime) endTime;
if(m_bRunning)
{
endTime = steady_clock::now();
}
else
{
endTime = m_EndTime;
}
return endTime - m_StartTime;
}