/
timer.h
49 lines (36 loc) · 916 Bytes
/
timer.h
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
#ifndef TIMER_H
#define TIMER_H
#include <chrono>
class Timer
{
using clock = std::chrono::high_resolution_clock;
using clock_t = std::chrono::time_point<std::chrono::high_resolution_clock>;
using duration_t = std::chrono::time_point<std::chrono::high_resolution_clock>::duration;
public:
enum class DurationType
{
NANOSECONDS,
MICROSECONDS,
MILISECONDS,
SECONDS,
MINUTES,
HOURS,
};
void setType(DurationType type = DurationType::MILISECONDS);
void start();
void stop();
static Timer * getInstance();
static void destroyInstance();
private:
DurationType _type;
clock_t _startTime;
clock_t _endTime;
duration_t _duration;
private:
static Timer *_instance;
Timer();
~Timer();
};
#define GetTimer() Timer::getInstance()
#define ReleaseTimer() Timer::destroyInstance()
#endif // TIMER_H