00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _CSCOPEDTIMING_H_
00021 #define _CSCOPEDTIMING_H_ 1
00022
00023 #ifdef _WIN32
00024 #include <windows.h>
00025 #else
00026 #include <sys/time.h>
00027 #endif
00028
00029 #include <iostream>
00030 #include <string>
00031
00032 namespace jsplib {
00048 class CScopedTiming {
00049
00050 private:
00051 double & m_out;
00052 #ifdef _WIN32
00053 DWORD m_start;
00054 #else
00055 struct timeval m_start;
00056 #endif
00057
00058
00059 static void *operator new(size_t size);
00060 static void operator delete(void *ptr);
00061 static void *operator new[](size_t size);
00062 static void operator delete[](void *ptr);
00063 CScopedTiming( const CScopedTiming & );
00064
00065
00066 public:
00068
00071 CScopedTiming( double & out ):m_out(out) {
00072 #ifdef _WIN32
00073 m_start = GetTickCount();
00074 #else
00075 gettimeofday(&m_start,NULL);
00076 #endif
00077 }
00079 ~CScopedTiming() {
00080 #ifdef _WIN32
00081 m_out += ((double)(GetTickCount() - m_start))/1000.0;
00082 #else
00083 struct timeval end, diff;
00084 gettimeofday(&end,NULL);
00085 timersub(&end,&m_start,&diff);
00086 m_out += (double)diff.tv_sec+((double)diff.tv_usec/1000000.0);
00087 #endif
00088 }
00089 };
00090
00091 }
00092
00093 #endif // _CSCOPEDTIMING_H_