-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathStopwatch.h
More file actions
37 lines (29 loc) · 1 KB
/
Stopwatch.h
File metadata and controls
37 lines (29 loc) · 1 KB
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
#ifndef CSL_STOPWATCH_H
#define CSL_STOPWATCH_H CSL_STOPWATCH_H
#include <chrono>
namespace csl {
class Stopwatch {
public:
Stopwatch();
inline void start();
inline unsigned long long readSeconds() const;
inline unsigned long long readMilliseconds() const;
private:
std::chrono::steady_clock::time_point start_;
};
inline Stopwatch::Stopwatch() {
start();
}
inline void Stopwatch::start() {
start_ = std::chrono::steady_clock::now();
}
inline unsigned long long Stopwatch::readSeconds() const {
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
return std::chrono::duration_cast<std::chrono::seconds>(now - start_).count();
}
inline unsigned long long Stopwatch::readMilliseconds() const {
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
return std::chrono::duration_cast<std::chrono::milliseconds>(now - start_).count();
}
} // ns csl
#endif