00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "TGLStopwatch.h"
00013 #include "TGLIncludes.h"
00014
00015 #ifdef R__WIN32
00016 #include <Windows.h>
00017 #else
00018 #include <sys/time.h>
00019 #endif
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 ClassImp(TGLStopwatch);
00031
00032
00033 TGLStopwatch::TGLStopwatch() : fStart(0), fEnd(0), fLastRun(0)
00034 {
00035
00036 }
00037
00038
00039 TGLStopwatch::~TGLStopwatch()
00040 {
00041
00042 }
00043
00044
00045 void TGLStopwatch::Start()
00046 {
00047
00048
00049 fStart = GetClock();
00050 fEnd = 0;
00051 }
00052
00053
00054
00055 Double_t TGLStopwatch::Lap() const
00056 {
00057
00058
00059 if (fStart == 0)
00060 return 0;
00061 else
00062 return GetClock() - fStart;
00063 }
00064
00065
00066
00067 Double_t TGLStopwatch::End()
00068 {
00069
00070
00071 if (fStart == 0)
00072 return 0;
00073 if (fEnd == 0) {
00074 fEnd = GetClock();
00075 fLastRun = fEnd - fStart;
00076 }
00077 return fLastRun;
00078 }
00079
00080
00081 Double_t TGLStopwatch::GetClock(void) const
00082 {
00083
00084
00085 #ifdef R__WIN32
00086
00087 static LARGE_INTEGER perfFreq;
00088 static Bool_t usePerformanceCounter = QueryPerformanceFrequency(&perfFreq);
00089
00090 if (usePerformanceCounter) {
00091 LARGE_INTEGER counter;
00092 QueryPerformanceCounter(&counter);
00093 Double_t time = static_cast<Double_t>(counter.QuadPart)*1000.0 /
00094 static_cast<Double_t>(perfFreq.QuadPart);
00095 return time;
00096 }
00097
00098
00099 FILETIME ft;
00100 ULARGE_INTEGER uli;
00101 __int64 t;
00102
00103 GetSystemTimeAsFileTime(&ft);
00104 uli.LowPart = ft.dwLowDateTime;
00105 uli.HighPart = ft.dwHighDateTime;
00106 t = uli.QuadPart;
00107 return static_cast<Double_t>(t /= 1E4);
00108 #else
00109 struct timeval tv;
00110 gettimeofday(&tv, 0);
00111 return static_cast<Double_t>(tv.tv_sec*1E3) + static_cast<Double_t>(tv.tv_usec) / 1E3;
00112 #endif
00113 }