-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timer.cpp
47 lines (40 loc) · 853 Bytes
/
Timer.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
#include "Timer.h"
Timer::Timer()
{
_start = std::chrono::high_resolution_clock::now();
_stop = std::chrono::high_resolution_clock::now();
}
double Timer::GetMillisecondElapsed()
{
if (_isRunnung)
{
auto elapsed = std::chrono::duration<double, std::milli>(std::chrono::high_resolution_clock::now() - _start);
return elapsed.count();
}
else
{
auto elapsed = std::chrono::duration<double, std::milli>(_stop - _start);
return elapsed.count();
}
}
void Timer::Restart()
{
_isRunnung = true;
_start = std::chrono::high_resolution_clock::now();
}
bool Timer::Stop()
{
if (!_isRunnung)
return false;
_stop = std::chrono::high_resolution_clock::now();
_isRunnung = false;
return true;
}
bool Timer::Start()
{
if (_isRunnung)
return false;
_start = std::chrono::high_resolution_clock::now();
_isRunnung = true;
return true;
}