-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimer.h
28 lines (24 loc) · 796 Bytes
/
Timer.h
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
#ifndef PROJECT_TIMER_H
#define PROJECT_TIMER_H
#include <iostream>
#include <string>
#include <chrono>
class Timer {
public:
Timer() : last(std::chrono::steady_clock::now()) {}
double get_time_diff() {
auto now = std::chrono::steady_clock::now();
std::chrono::duration<double> diff = now - last;
last = std::chrono::steady_clock::now();
return diff.count();
}
void time (const std::string& msg = "Time Taken: ") {
auto now = std::chrono::steady_clock::now();
std::chrono::duration<double> diff = now - last;
std::cout << msg << diff.count() << "[s]\n";
last = std::chrono::steady_clock::now();
}
private:
std::chrono::steady_clock::time_point last;
};
#endif //PROJECT_TIMER_H