00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef TIMER_H
00020 #define TIMER_H
00021
00022 #include "sys/time.h"
00023
00033
00034 namespace TIMER {
00035
00036 static struct timeval _tstart;
00037 static struct timezone tz;
00038
00054
00055 inline void SetStartTime (void)
00056 {
00057 gettimeofday (&_tstart,
00058 &tz);
00059 }
00060
00074
00075 inline double TimeElapsed (void)
00076 {
00077 double t1,t2;
00078
00079
00080
00081 struct timeval tnow;
00082
00083 gettimeofday (&tnow,
00084 &tz);
00085
00086
00087
00088 t1 = (double) _tstart.tv_sec + (double) _tstart.tv_usec/(1000*1000);
00089
00090 t2 = (double) tnow.tv_sec + (double) tnow.tv_usec/(1000*1000);
00091
00092
00093
00094 return t2 - t1;
00095 }
00096
00110
00111 inline double TimeElapsed (const struct timeval &time)
00112 {
00113 double t1,t2;
00114
00115
00116
00117 struct timeval tnow;
00118
00119 gettimeofday (&tnow,
00120 &tz);
00121
00122
00123
00124 t1 = (double) time.tv_sec + (double) time.tv_usec/(1000*1000);
00125
00126 t2 = (double) tnow.tv_sec + (double) tnow.tv_usec/(1000*1000);
00127
00128
00129
00130 return t2 - t1;
00131 }
00132
00133 }
00134
00135 #endif // TIMER_H