-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtimer.hpp
34 lines (33 loc) · 879 Bytes
/
timer.hpp
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
#include <chrono>
namespace mytimer {
class timer {
private:
std::chrono::system_clock::time_point startTime;
inline std::chrono::system_clock::time_point getTime() {
return std::chrono::system_clock::now();
}
public:
inline void set() {
startTime = getTime();
}
inline double getMsec() {
auto dur = getTime() - startTime;
auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(dur).count();
return msec;
}
inline double getSec() {
return (double)getMsec()/1000.0;
}
inline double get() {
return getSec();
}
inline void print(const std::string str= "") {
double t = get();
if(t > 1) std::cout << str << " " << t << " sec." << std::endl;
else std::cout << str << " " << t*1000.0 << "msec." << std::endl;
}
timer() {
set();
}
};
};