00001
00002
00003
00004
00005
00006
00007
00008 #ifndef FV_TIMER_H_
00009 #define FV_TIMER_H_
00010
00011 #ifdef WIN32
00012 #include <windows.h>
00013 #include <stdlib.h>
00014 #else
00015 #include <sys/time.h>
00016 #include <stdlib.h>
00017 #endif
00018
00019 class fv_timer {
00020 public:
00021 fv_timer();
00022 ~fv_timer();
00023
00024 inline void start();
00025 inline void stemp();
00026 inline void stop();
00027
00028 double get_time_sec() { return get_time_us() * 1e-6; }
00029 double get_time_ms() { return get_time_us() * 1e-3; }
00030 double get_time_us();
00031
00032 double get_duration_sec() { return get_duration_us() * 1e-6; }
00033 double get_duration_ms() { return get_duration_us() * 1e-3; }
00034 double get_duration_us();
00035
00036 private:
00037 double stime_us;
00038 double etime_us;
00039 double ltime_us;
00040 int running;
00041
00042 #ifdef WIN32
00043 LARGE_INTEGER freq;
00044 LARGE_INTEGER scount;
00045 LARGE_INTEGER ecount;
00046 LARGE_INTEGER lcount;
00047 double milion_over_freq;
00048 #else
00049 timeval scount;
00050 timeval ecount;
00051 timeval lcount;
00052 #endif
00053 };
00054
00055 void fv_timer::start()
00056 {
00057 #ifdef WIN32
00058 QueryPerformanceCounter(&_start);
00059 #else
00060 gettimeofday(&scount, NULL);
00061 #endif
00062 lcount = scount;
00063 }
00064
00065 void fv_timer::stemp()
00066 {
00067 #ifdef WIN32
00068 QueryPerformanceCounter(&lcount);
00069 #else
00070 gettimeofday(&lcount, NULL);
00071 #endif
00072 }
00073
00074 void fv_timer::stop()
00075 {
00076 #ifdef WIN32
00077 QueryPerformanceCounter(&ecount);
00078 #else
00079 gettimeofday(&ecount, NULL);
00080 #endif
00081 lcount = ecount;
00082 running = 0;
00083 }
00084
00085
00086 #endif