Timer.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _TIMER_H
00025 #define _TIMER_H
00026
00027
00028 #ifdef HAVE_SYS_TIME_H
00029
00030 #include <sys/time.h>
00031
00032
00034
00035 class Timer {
00036
00037
00038 private:
00039
00041 struct timeval tv;
00042
00044 struct timezone tz;
00045
00047 long start_t;
00048
00050 long start_u;
00051
00052
00053 public:
00054
00056 Timer() {;};
00057
00058
00060
00061 void start() {
00062 tz.tz_minuteswest = 0;
00063 if( gettimeofday( &tv, &tz ) == 0 ){
00064 start_t = tv.tv_sec;
00065 start_u = tv.tv_usec;
00066 }
00067 else start_t = start_u = 0;
00068 }
00069
00070
00072 long getTime() {
00073 if( gettimeofday( &tv, &tz ) == 0 ) return (tv.tv_sec - start_t) * 1000000 + (tv.tv_usec - start_u);
00074 else return 0;
00075 }
00076
00077
00078 };
00079
00080
00081
00082 #else
00083
00085
00086 class Timer {
00087
00088 public:
00089
00091 Timer() {;};
00092
00094 void start() {;};
00095
00097 long getTime(){ return 0; }
00098
00099 };
00100
00101
00102 #endif
00103
00104 #endif
00105