-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.hpp
More file actions
23 lines (20 loc) · 756 Bytes
/
timer.hpp
File metadata and controls
23 lines (20 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <memory>
#include <chrono>
//Resource Acquisition Is Initialization(RAII)
class Timer
{
public:
Timer() { start_time_point = std::chrono::high_resolution_clock::now(); }
~Timer() { Stop(); }
void Stop()
{
auto end_time_point = std::chrono::high_resolution_clock::now();
auto start = std::chrono::time_point_cast<std::chrono::microseconds>(start_time_point).time_since_epoch().count();
auto end = std::chrono::time_point_cast<std::chrono::microseconds>(end_time_point).time_since_epoch().count();
auto duration = end - start;
std::cout << duration << "us" << std::endl;
}
private:
std::chrono::time_point<std::chrono::high_resolution_clock> start_time_point;
};