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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include<ctime>
#include "MyTimer.h"
#include "common.h"
void MyTimer::adjust(double &time,char f){//{{{
if(f=='m')time/=60.0;
if(f=='h')time/=3600.0;
}//}}}
void MyTimer::write(double time,char f){//{{{
if(!quiet)messageF("[time: +%.2lf %c]\n",time,f);
}//}}}
MyTimer::MyTimer(){//{{{
N=1;
quiet=false;
times.resize(N);
times[0]=time(NULL);
}//}}}
void MyTimer::start(long timer){//{{{
if(timer>=N){
N=timer+1;
times.resize(N);
}
times[timer]=time(NULL);
}//}}}
double MyTimer::split(long timer, char f){//{{{
if(timer>=N)return 0;
double ret;
ret=time(NULL)-times[timer];
adjust(ret,f);
write(ret,f);
times[timer]=time(NULL);
return ret;
}//}}}
double MyTimer::getTime(long timer, char f){//{{{
if(timer>=N)return 0;
double ret;
ret=time(NULL)-times[timer];
adjust(ret,f);
return ret;
}//}}}
double MyTimer::current(long timer, char f){//{{{
if(timer>=N)return 0;
double ret;
ret=time(NULL)-times[timer];
adjust(ret,f);
write(ret,f);
return ret;
}//}}}
double MyTimer::stop(long timer, char f){//{{{
if(timer>=N)return 0;
double ret;
ret=time(NULL)-times[timer];
adjust(ret,f);
write(ret,f);
times[timer]=time(NULL);
return ret;
}//}}}
|