-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtimer.cpp
47 lines (39 loc) · 1.27 KB
/
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>
namespace util
{
//----------------------------------------------------------------------------------------------------------------------------------------------------------
// Timer:public
//----------------------------------------------------------------------------------------------------------------------------------------------------------
Timer::Timer()
{
restart();
}
static inline std::conditional<std::chrono::high_resolution_clock::is_steady,
std::chrono::high_resolution_clock,
std::chrono::steady_clock>::type::time_point getNow()
{
return std::conditional<std::chrono::high_resolution_clock::is_steady,
std::chrono::high_resolution_clock,
std::chrono::steady_clock>::type::now();
}
void Timer::restart()
{
_start = getNow();
}
double Timer::elapsedSec()
{
return elapsedNanoSec() * 1e-9;
}
double Timer::elapsedMilliSec()
{
return elapsedNanoSec() * 1e-6;
}
double Timer::elapsedMicroSec()
{
return elapsedNanoSec() * 1e-3;
}
double Timer::elapsedNanoSec()
{
return static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(getNow() - _start).count());
}
}