-
Notifications
You must be signed in to change notification settings - Fork 0
/
StopWatch.cpp
38 lines (27 loc) · 877 Bytes
/
StopWatch.cpp
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
#include "StopWatch.h"
#include "Log.h"
StopWatch::StopWatch( string iname, bool iAutoprint ) :
name( iname ), autoprint( iAutoprint ) {
reset();
}
StopWatch::~StopWatch() {
if( autoprint ) {
info( "%s took %f seconds", name.c_str(), sec() );
}
}
void StopWatch::reset() {
start = std::chrono::high_resolution_clock::now();
}
unsigned long long StopWatch::milli() const {
std::chrono::high_resolution_clock::time_point stop = std::chrono::high_resolution_clock::now();
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(stop - start);
return ms.count();
}
double StopWatch::sec() const {
std::chrono::high_resolution_clock::time_point stop = std::chrono::high_resolution_clock::now();
return std::chrono::duration<double>(stop - start).count();
}
void StopWatch::spin( double fps ) {
reset();
while( sec() < 1/fps );
}