-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stopwatch.cpp
45 lines (35 loc) · 989 Bytes
/
Stopwatch.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
#ifndef _SCRIPT_PAD_STOP_WATCH_CPP
#define _SCRIPT_PAD_STOP_WATCH_CPP
#include "Stopwatch.h"
namespace querier {
void Stopwatch::Start() {
m_start = system_clock::now();
m_bRunning = true;
}
void Stopwatch::Stop() {
m_end = system_clock::now();
m_bRunning = false;
}
void Stopwatch::StopMs(double* result) {
Stop();
*result = elapsedMilliSeconds();
}
void Stopwatch::StopS(double* result) {
Stop();
*result = elapsedSeconds();
}
double Stopwatch::elapsedMilliSeconds() {
time_point<system_clock> endTime;
if (m_bRunning) {
endTime = system_clock::now();
}
else {
endTime = m_end;
}
return duration_cast<milliseconds>(endTime - m_start).count();
}
double Stopwatch::elapsedSeconds() {
return elapsedMilliSeconds() / 1000.0;
}
} //namespace stopwatch
#endif //_SCRIPT_PAD_STOP_WATCH_CPP