-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtime_meas.h
More file actions
36 lines (34 loc) · 857 Bytes
/
time_meas.h
File metadata and controls
36 lines (34 loc) · 857 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
// time_meas.h :
// Simple warpper class to measure time.
// Written by Klaus Beyer, 2015
//
// Examples:
// TimeMeaseremtn tm;
// ... a lot of code
// tm.stop();
// std::cout << "Time elapsed so far (ms) " << tm.diffTime<std::chrono::milliseconds>() << std::endl;
//
#pragma once
#include <chrono>
class TimeMeasurement
{
public:
TimeMeasurement() { start(); }
template<typename T>
long long diffTime()
{
return std::chrono::duration_cast<T>(endTime - startTime).count();
}
void stop()
{
endTime = std::chrono::high_resolution_clock::now();
}
void start()
{
startTime = std::chrono::high_resolution_clock::now();
endTime = startTime;
}
private:
std::chrono::time_point< std::chrono::high_resolution_clock> startTime;
std::chrono::time_point< std::chrono::high_resolution_clock> endTime;
};