m8
/
src
/
ob
/
timer.hh
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
#ifndef OB_TIMER_HH
#define OB_TIMER_HH
#include <string>
#include <sstream>
#include <iostream>
#include <chrono>
namespace OB
{
class Timer
{
public:
Timer()
{
}
~Timer()
{
}
void start()
{
_start = std::chrono::high_resolution_clock::now();
}
void stop()
{
_stop = std::chrono::high_resolution_clock::now();
}
template<class T = std::chrono::nanoseconds>
long int time()
{
return std::chrono::duration_cast<T>(_stop - _start).count();
}
long int time()
{
return std::chrono::duration_cast<std::chrono::nanoseconds>(_stop - _start).count();
}
private:
std::chrono::time_point<std::chrono::high_resolution_clock> _start;
std::chrono::time_point<std::chrono::high_resolution_clock> _stop;
}; // class Timer
} // namespace OB
#endif // OB_TIMER_HH