-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathStopwatch.h
More file actions
49 lines (38 loc) · 808 Bytes
/
Copy pathStopwatch.h
File metadata and controls
49 lines (38 loc) · 808 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
47
48
49
#ifndef STOPWATCH_H
#define STOPWATCH_H
#include <limits>
#include <ctime>
#include <chrono>
class Stopwatch
{
public:
Stopwatch()
: in_use_(false)
{}
inline void Start()
{
in_use_ = true;
start_time_ = std::chrono::steady_clock::now();
}
inline double Stop()
{
stop_time_ = std::chrono::steady_clock::now();
in_use_ = false;
return time();
}
inline bool in_use() const
{
return in_use_;
}
private:
inline double time() const
{
const auto duration = stop_time_ - start_time_;
return std::chrono::duration<double,std::nano>(duration).count();
}
typedef std::chrono::time_point<std::chrono::steady_clock> time_point_t;
time_point_t start_time_;
time_point_t stop_time_;
bool in_use_;
};
#endif