-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime.h
50 lines (38 loc) · 1.08 KB
/
time.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
#pragma once
#include <chrono>
namespace core
{
typedef std::conditional<std::chrono::high_resolution_clock::is_steady,
std::chrono::high_resolution_clock, std::chrono::steady_clock >::type clock;
typedef clock::time_point time_point;
typedef clock::duration time;
typedef std::chrono::nanoseconds nano_sec;
typedef std::chrono::microseconds micro_sec;
typedef std::chrono::milliseconds milli_sec;
typedef std::chrono::seconds sec;
template <typename T>
inline double time_cast(const time& time)
{
return std::chrono::duration_cast<T>(time).count();
}
template<>
inline double time_cast<nano_sec>(const time& t)
{
return std::chrono::duration_cast<nano_sec>(t).count();
}
template<>
inline double time_cast<micro_sec>(const time& t)
{
return std::chrono::duration_cast<micro_sec>(t).count();
}
template<>
inline double time_cast<milli_sec>(const time& t)
{
return std::chrono::duration<double, std::ratio<1, 1000>>(t).count();
}
template<>
inline double time_cast<sec>(const time& t)
{
return std::chrono::duration<double>(t).count();
}
}