-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.h
More file actions
44 lines (33 loc) · 1 KB
/
timer.h
File metadata and controls
44 lines (33 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
38
39
40
41
42
43
44
/*
* Vectorix -- line-based image vectorizer
* (c) 2016 Jan Hadrava <had@atrey.karlin.mff.cuni.cz>
*/
#ifndef VECTORIX__TIME_MEASUREMENT_H
#define VECTORIX__TIME_MEASUREMENT_H
// Time measurement
#include "config.h"
#include <chrono>
#include <ctime>
namespace vectorix {
class timer {
public:
timer(double prewarm_time = 0.): prewarm_time_(prewarm_time) {}; // Prewarm the CPU for prewarm_time (in seconds)
inline void start() { // Start measuring time
auto time = std::chrono::system_clock::now();
while (std::chrono::system_clock::now() - time < prewarm_time_)
;
start_ = std::chrono::system_clock::now();
};
inline void stop() { // Stop measuring time
stop_ = std::chrono::system_clock::now();
};
inline double read() { // Get time spent (in seconds)
std::chrono::duration<double> duration = stop_ - start_;
return duration.count();
};
private:
std::chrono::time_point<std::chrono::system_clock> start_, stop_;
std::chrono::duration<double> prewarm_time_;
};
}; // namespace
#endif