#include "TGLStopwatch.h"
#include "TGLIncludes.h"
#ifdef R__WIN32
#include <Windows.h> // For GetSystemTimeAsFileTime()
#else
#include <sys/time.h> // For gettimeofday()
#endif
ClassImp(TGLStopwatch)
Bool_t TGLStopwatch::fgInitOverhead = kFALSE;
Double_t TGLStopwatch::fgOverhead = 0.0;
TGLStopwatch::TGLStopwatch()
{
if (!fgInitOverhead)
{
InitOverhead();
}
}
TGLStopwatch::~TGLStopwatch()
{
}
void TGLStopwatch::Start()
{
FinishDrawing();
fStart = WaitForTick();
}
Double_t TGLStopwatch::Lap() const
{
FinishDrawing();
Double_t elapsed = GetClock() - fStart - fgOverhead;
return elapsed > 0.0 ? elapsed : 0.0;
}
Double_t TGLStopwatch::End()
{
return Lap();
}
Double_t TGLStopwatch::GetClock(void) const
{
#ifdef R__WIN32
static LARGE_INTEGER perfFreq;
static Bool_t usePerformanceCounter = QueryPerformanceFrequency(&perfFreq);
if (usePerformanceCounter) {
LARGE_INTEGER counter;
QueryPerformanceCounter(&counter);
Double_t time = static_cast<Double_t>(counter.QuadPart)*1000.0 /
static_cast<Double_t>(perfFreq.QuadPart);
return time;
}
FILETIME ft;
ULARGE_INTEGER uli;
__int64 t;
GetSystemTimeAsFileTime(&ft);
uli.LowPart = ft.dwLowDateTime;
uli.HighPart = ft.dwHighDateTime;
t = uli.QuadPart;
return static_cast<Double_t>(t /= 1E4);
#else
struct timeval tv;
gettimeofday(&tv, 0);
return static_cast<Double_t>(tv.tv_sec*1E3) + static_cast<Double_t>(tv.tv_usec) / 1E3;
#endif
}
void TGLStopwatch::FinishDrawing(void) const
{
glFinish();
}
Double_t TGLStopwatch::WaitForTick(void) const
{
Double_t start;
Double_t current;
start = GetClock();
while ((current = GetClock()) == start);
return current;
}
void TGLStopwatch::InitOverhead(void) const
{
Double_t runTime;
Long_t reps;
Double_t start;
Double_t finish;
Double_t current;
start = GetClock();
while ((finish = GetClock()) == start);
runTime = 100.0 * (finish - start);
if (runTime < 100)
runTime = 100;
else if (runTime > 500)
runTime = 1000;
FinishDrawing();
reps = 0;
start = WaitForTick();
finish = start + runTime;
do {
FinishDrawing();
++reps;
} while ((current = GetClock()) < finish);
fgOverhead = (current - start) / (Double_t) reps;
fgInitOverhead = true;
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.