-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBbStopWatch.hpp
45 lines (37 loc) · 920 Bytes
/
BbStopWatch.hpp
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
#ifndef GUARD_BBSTOPWATCH_HPP
#define GUARD_BBSTOPWATCH_HPP
#include <chrono>
class BbStopWatch
{
public:
enum class TimeUOM
{
hours,
minutes,
seconds,
milliseconds,
microseconds,
nanoseconds
};
typedef std::chrono::high_resolution_clock hr_clock;
typedef std::chrono::time_point<std::chrono::high_resolution_clock> hr_t_point;
private:
hr_t_point startTime;
hr_t_point splitTime;
hr_t_point stopTime;
bool isRunning = false;
TimeUOM period;
double get_duration(const hr_t_point& e, const hr_t_point& s, const TimeUOM& p) const;
public:
explicit BbStopWatch(TimeUOM p)
: period(p) { }
void start();
void stop();
void reset();
void restart();
double split();
double get_total_running_time() const;
void change_uom(const TimeUOM& newPeriod) { period = newPeriod; }
bool is_running() const { return isRunning; }
};
#endif // GUARD_BBSTOPWATCH_HPP