-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTimer.cpp
43 lines (34 loc) · 981 Bytes
/
Timer.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
37
38
39
40
41
42
#include "Timer.h"
using namespace std::chrono ;
void Timer::start(){
running = true;
start_time = high_resolution_clock::now() ;
}
void Timer::stop(){
end_time = high_resolution_clock::now() ;
running=false;
}
void Timer::reset(){
start_time = high_resolution_clock::now() ;
end_time = start_time;
running = false;
}
long int Timer::getMicroTime(){
//duration<std::chrono::microseconds> time_span ;
long int time_span;
if( running ){
time_span = duration_cast<std::chrono::microseconds>(high_resolution_clock::now()-start_time).count();
} else {
time_span = duration_cast<std::chrono::microseconds>(end_time-start_time).count();
}
return time_span;
}
double Timer::getTime(){
duration<double> time_span ;
if( running ){
time_span = duration_cast<duration<double>>( high_resolution_clock::now() - start_time );
} else {
time_span = duration_cast<duration<double>>(end_time - start_time);
}
return time_span.count() ;
}