00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _mitkPerformanceCounter_h
00011 #define _mitkPerformanceCounter_h
00012
00013 #ifdef _WIN32
00014 #include <windows.h>
00015 class mitkPerformanceCounter
00016 {
00017 double dfFreq ;
00018 public:
00019 mitkPerformanceCounter()
00020 {
00021 LARGE_INTEGER litmp;
00022 QueryPerformanceFrequency(&litmp);
00023 dfFreq = (double)litmp.QuadPart/1000;
00024 }
00025 double GetTime()
00026 {
00027 LARGE_INTEGER litmp;
00028 QueryPerformanceCounter(&litmp);
00029 return (double)litmp.QuadPart/dfFreq;
00030 }
00031 };
00032
00033 static mitkPerformanceCounter theCounter;
00034
00035 static inline double GetTime()
00036 {
00037 return theCounter.GetTime();
00038 }
00039
00040 #else
00041
00042 #include <sys/time.h>
00043 static inline double GetTime()
00044 {
00045 struct timeval t_time;
00046 gettimeofday( &t_time, 0);
00047 return 1000.0 * t_time.tv_sec + 0.001 * t_time.tv_usec;
00048 }
00049
00050 #endif
00051
00052 class TimeAverager
00053 {
00054 public:
00055 TimeAverager()
00056 {
00057 totalTime=0.0;
00058 count=0;
00059 maxCount=50;
00060 }
00061 ~TimeAverager()
00062 {
00063 }
00064 void SetMaxCount(unsigned maxCount)
00065 {
00066 this->maxCount=maxCount;
00067 }
00068 void Start()
00069 {
00070 startTime=GetTime();
00071 }
00072 void Stop()
00073 {
00074 if (count==maxCount)
00075 {
00076 printf("MaxCount Reached!\n");
00077 totalTime=0.0;
00078 count=0;
00079 }
00080 totalTime+=GetTime()-startTime;
00081 count++;
00082 }
00083 double GetAverageTime()
00084 {
00085 return totalTime/(double)count;
00086 }
00087
00088 private:
00089 double startTime;
00090 double totalTime;
00091 unsigned count;
00092 unsigned maxCount;
00093 };
00094
00095 #endif