00001 #ifndef _PROFTIMER_HPP_
00002 #define _PROFTIMER_HPP_
00003
00009 #ifdef WIN32
00010 #define WIN
00011 #endif
00012
00013 #ifdef WIN
00014 #include <windows.h>
00015 #else // LINUX
00016 #include <time.h>
00017 #endif
00018
00019
00020
00021 struct ProfTimer {
00022 void Start(void)
00023 {
00024 #ifdef WIN
00025 QueryPerformanceCounter(&mTimeStart);
00026 #else
00027 clock_gettime(CLOCK_REALTIME,&mTimeStart);
00028 #endif
00029 }
00030
00031 void Stop(void)
00032 {
00033 #ifdef WIN
00034 QueryPerformanceCounter(&mTimeStop);
00035 #else
00036 clock_gettime(CLOCK_REALTIME, &mTimeStop);
00037 #endif
00038 }
00039
00040 double GetDurationInSecs(void) const
00041 {
00042 #ifdef WIN
00043 LARGE_INTEGER freq;
00044 QueryPerformanceFrequency(&freq);
00045 return ((double)(mTimeStop.QuadPart-mTimeStart.QuadPart)/(double)freq.QuadPart);
00046 #else
00047 return double(mTimeStop.tv_sec - mTimeStart.tv_sec) + (double(mTimeStop.tv_nsec - mTimeStart.tv_nsec)/double(1000000000));
00048 #endif
00049 }
00050
00051 #ifdef WIN
00052 LARGE_INTEGER mTimeStart;
00053 LARGE_INTEGER mTimeStop;
00054 #else
00055 timespec mTimeStart;
00056 timespec mTimeStop;
00057 #endif
00058 };
00059
00060
00063 #endif // _PROFTIMER_HPP_