-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.hpp
More file actions
33 lines (26 loc) · 679 Bytes
/
Timer.hpp
File metadata and controls
33 lines (26 loc) · 679 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
#ifndef TIMER_HPP_
# define TIMER_HPP_
# include <chrono>
# include <thread>
template<class T = std::chrono::milliseconds>
class Timer
{
public:
Timer() : start_(std::chrono::high_resolution_clock::now())
{}
inline void reset()
{
start_ = std::chrono::high_resolution_clock::now();
}
inline double elapsed() const
{
return std::chrono::duration_cast<T>(std::chrono::high_resolution_clock::now() - start_).count();
}
inline void sleep(int n) const
{
std::this_thread::sleep_for(T(n));
}
private:
std::chrono::time_point<std::chrono::high_resolution_clock> start_;
};
#endif /* end of include guard */