/vol/vipdata/irtk/common++/include/irtkTimer.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _IRTKTIMER_H
00014
00015 #define _IRTKTIMER_H
00016
00017 #include <time.h>
00018
00019 #ifndef WIN32
00020 #include <sys/times.h>
00021 #endif
00022
00023
00024
00025
00026
00027 #include <irtkObject.h>
00028
00029 class irtkTimer : public irtkObject
00030 {
00031
00032 public:
00033
00035 irtkTimer() {
00036
00037
00038 this->Reset();
00039 };
00040
00042 virtual ~irtkTimer() {};
00043
00045 float Report();
00046
00048 void Reset();
00049
00050 private:
00051
00052 #ifndef WIN32
00053
00055 long _usr_time;
00056
00058 struct tms _cpu_time;
00059
00060 #endif
00061
00062 };
00063
00064 inline float irtkTimer::Report()
00065 {
00066 #ifndef WIN32
00067 times(&_cpu_time);
00068 _usr_time += _cpu_time.tms_utime;
00069 return _usr_time/(float)CLOCKS_PER_SEC;
00070 #else
00071 return 0;
00072 #endif
00073 }
00074
00075 inline void irtkTimer::Reset()
00076 {
00077 #ifndef WIN32
00078 times(&_cpu_time);
00079 _usr_time = -_cpu_time.tms_utime;
00080 #endif
00081 }
00082
00083 #endif