-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.hpp
More file actions
46 lines (36 loc) · 941 Bytes
/
clock.hpp
File metadata and controls
46 lines (36 loc) · 941 Bytes
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
#ifndef CLOCK_HPP
#define CLOCK_HPP
#include <chrono>
class Time{
private:
std::chrono::nanoseconds m_Value;
public:
Time(std::chrono::nanoseconds value = std::chrono::nanoseconds()):
m_Value(value)
{}
float AsSeconds(){
return (float)AsNanoseconds() / 1000000000.f;
}
int AsMilliseconds(){
return AsNanoseconds() / 1000000;
}
int64_t AsNanoseconds(){
return m_Value.count();
}
};
class Clock{
private:
std::chrono::time_point<std::chrono::steady_clock> m_Begin;
public:
Clock():
m_Begin(std::chrono::steady_clock::now())
{}
Time GetElapsedTime(){
std::chrono::time_point<std::chrono::steady_clock> now = std::chrono::steady_clock::now();
return Time(std::chrono::duration_cast<std::chrono::nanoseconds>(now - m_Begin));
}
void Reset(){
m_Begin = std::chrono::steady_clock::now();
}
};
#endif//CLOCK_HPP