-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdjl_durat.hxx
48 lines (37 loc) · 1.13 KB
/
djl_durat.hxx
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
#pragma once
#include <chrono>
using namespace std;
using namespace std::chrono;
class CDuration
{
private:
high_resolution_clock::time_point tLast;
public:
CDuration()
{
tLast = high_resolution_clock::now();
}
~CDuration() {}
bool HasTimeElapsed( long long target )
{
high_resolution_clock::time_point tNow = high_resolution_clock::now();
long long duration = duration_cast<std::chrono::nanoseconds>( tNow - tLast ).count();
if ( duration >= target )
{
tLast = tNow;
return true;
}
return false;
}
bool HasTimeElapsedMS( long long target )
{
high_resolution_clock::time_point tNow = high_resolution_clock::now();
long long duration = duration_cast<std::chrono::milliseconds>( tNow - tLast ).count();
if ( duration >= target )
{
tLast = tNow;
return true;
}
return false;
}
};