forked from qicosmos/cosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timer.hpp
57 lines (47 loc) · 1.23 KB
/
Timer.hpp
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
51
52
53
54
55
56
#pragma once
#include<chrono>
using namespace std;
using namespace std::chrono;
class Timer
{
public:
Timer() : m_begin(high_resolution_clock::now()) {}
void reset() { m_begin = high_resolution_clock::now(); }
//默认输出毫秒
int64_t elapsed() const
{
return duration_cast<chrono::milliseconds>(high_resolution_clock::now() - m_begin).count();
}
//默认输出秒
double elapsed_second() const
{
return duration_cast<duration<double>>(high_resolution_clock::now() - m_begin).count();
}
//微秒
int64_t elapsed_micro() const
{
return duration_cast<chrono::microseconds>(high_resolution_clock::now() - m_begin).count();
}
//纳秒
int64_t elapsed_nano() const
{
return duration_cast<chrono::nanoseconds>(high_resolution_clock::now() - m_begin).count();
}
////秒
//int64_t elapsed_seconds() const
//{
// return duration_cast<chrono::seconds>(high_resolution_clock::now() - m_begin).count();
//}
//分
int64_t elapsed_minutes() const
{
return duration_cast<chrono::minutes>(high_resolution_clock::now() - m_begin).count();
}
//时
int64_t elapsed_hours() const
{
return duration_cast<chrono::hours>(high_resolution_clock::now() - m_begin).count();
}
private:
time_point<high_resolution_clock> m_begin;
};