3 #ifndef CH_TOOLS__CLOCK_HXX 4 #define CH_TOOLS__CLOCK_HXX 21 #include <sys/resource.h> 22 #include <sys/timeb.h> 65 {seconds=secs; microsecs=msecs;infinity=
false;}
69 {seconds=secs; microsecs=msecs;infinity=
false;}
72 {seconds=hours*3600+minutes*60+secs; microsecs=micros;infinity=
false;}
75 {seconds=hours*3600+minutes*60+secs; microsecs=micros;infinity=
false;}
97 while (microsecs>1000000){
109 while (microsecs<0) {
110 seconds--; microsecs+=1000000;
125 if (infinity)
return false;
133 if (infinity&&(!m.
infinity))
return true;
140 if (infinity&&(!m.
infinity))
return false;
147 if (infinity)
return true;
169 operator double()
const 170 {
return double(seconds)+double(microsecs)/1000000.; }
173 void hhmmss(
long& hours,
long& minutes,
long& secs)
const 176 if (microsecs>=500000) s++;
183 void hhmmssdd(
long& hours,
long& minutes,
long& secs,
long& hund)
const 185 hund=(microsecs+5000)/10000;
187 if (hund==100) {s++;hund=0;}
196 if (microsecs>=500000)
return seconds+1;
203 long hund=(microsecs+5000)/10000;
216 {
if (m.
infinity)
return out<<
"-1.000000";
218 out.fill(
' ');
return out;}
236 long hours,minutes,
seconds,hunds;
239 m.
hhmmss(hours,minutes,seconds);
240 out.width(2);out<<hours;
241 out<<
":";out.width(2);out<<minutes;
242 out<<
":";out.width(2);out<<
seconds;
245 m.
hhmmssdd(hours,minutes,seconds,hunds);
246 out.width(2);out<<hours;
247 out<<
":";out.width(2);out<<minutes;
248 out<<
":";out.width(2);out<<
seconds;
249 out<<
".";out.width(2);out<<hunds;
265 return Microseconds(
long(ts.time),
long(ts.millitm)*1000);
297 struct rusage r_usage;
298 getrusage(RUSAGE_SELF,&r_usage);
299 t_start=
Microseconds(r_usage.ru_utime.tv_sec,r_usage.ru_utime.tv_usec);
320 struct rusage r_usage;
321 getrusage(RUSAGE_SELF,&r_usage);
322 Microseconds elapsed(r_usage.ru_utime.tv_sec,r_usage.ru_utime.tv_usec);
339 time_t current=::time(0);
342 out<<
"elapsed time: ";
346 loctime=localtime(¤t);
347 out<<
" ---- "<<asctime(loctime)<<std::flush;
Microseconds wall_clock(void)
returns the wall clock time since Epoch
Definition: clock.hxx:260