forked from msdohehrty/dsa555-s16
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.cpp
39 lines (38 loc) · 833 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
#include "timer.h"
/*
start(); starts the clock running from the current time
currtime(); returns the current time
stop(); stops the clock without reseting its value
reset(); stops the clock and resets the timer to 0
*/
Timer::Timer(){
starttime_=0;
isstop_=1;
stoptime_=0;
}
void Timer::reset(){
stoptime_=0;
starttime_=0;
isstop_=1;
}
void Timer::start(){
clock_t curr=clock();
if(isstop_){
starttime_=(stoptime_==0)?curr:starttime_+(curr-stoptime_);
}
else{
starttime_=curr; //its like hitting reset and start
}
}
void Timer::stop(){
stoptime_=clock();
isstop_=1;
}
double Timer::currtime(){
clock_t curr=clock();
clock_t elapse=(isstop_)?stoptime_-starttime_:curr-starttime_;
return double(elapse)/CLOCKS_PER_SEC;
}
double Timer::starttime(){
return (double)starttime_;
}