-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.h
More file actions
29 lines (22 loc) · 690 Bytes
/
timer.h
File metadata and controls
29 lines (22 loc) · 690 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
#ifndef TIMER_H
#define TIMER_H
#include <chrono>
class Timer {
public:
string name;
std::chrono::steady_clock::time_point g_start;
std::chrono::steady_clock::time_point g_end;
Timer(string name) {
this->name = name;
start();
}
void start() {
g_start = std::chrono::high_resolution_clock::now();
}
void stop() {
g_end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(g_end - g_start);
printf("%s took %lld milliseconds.\n", name.c_str(), duration.count());
}
};
#endif