Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGLStopwatch.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Richard Maunder 25/05/2005
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TGLStopwatch.h"
13#include "TGLIncludes.h"
14
15#ifdef R__WIN32
16#include <Windows.h> // For GetSystemTimeAsFileTime()
17#else
18#include <sys/time.h> // For gettimeofday()
19#endif
20
21/** \class TGLStopwatch
22\ingroup opengl
23Stopwatch object for timing GL work. We do not use the TStopwatch as
24we need to perform GL flushing to get accurate times + we record
25timing overheads here.
26*/
27
29
30////////////////////////////////////////////////////////////////////////////////
31/// Construct stopwatch object.
32
33TGLStopwatch::TGLStopwatch() : fStart(0), fEnd(0), fLastRun(0)
34{
35}
36
37////////////////////////////////////////////////////////////////////////////////
38/// Destroy stopwatch object.
39
41{
42}
43
44////////////////////////////////////////////////////////////////////////////////
45/// Start timing.
46
48{
49 fStart = GetClock();
50 fEnd = 0;
51}
52
53// In milliseconds
54////////////////////////////////////////////////////////////////////////////////
55/// Return lap time since Start(), in milliseconds.
56
58{
59 if (fStart == 0)
60 return 0;
61 else
62 return GetClock() - fStart;
63}
64
65// In milliseconds
66////////////////////////////////////////////////////////////////////////////////
67/// End timing, return total time since Start(), in milliseconds.
68
70{
71 if (fStart == 0)
72 return 0;
73 if (fEnd == 0) {
74 fEnd = GetClock();
76 }
77 return fLastRun;
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// Get internal clock time, in milliseconds.
82
84{
85#ifdef R__WIN32
86 // Use performance counter (system dependent support) if possible
87 static LARGE_INTEGER perfFreq;
88 static Bool_t usePerformanceCounter = QueryPerformanceFrequency(&perfFreq);
89
90 if (usePerformanceCounter) {
91 LARGE_INTEGER counter;
92 QueryPerformanceCounter(&counter);
93 Double_t time = static_cast<Double_t>(counter.QuadPart)*1000.0 /
94 static_cast<Double_t>(perfFreq.QuadPart);
95 return time;
96 }
97
98 // TODO: Portability - check with Rene
99 FILETIME ft;
100 ULARGE_INTEGER uli;
101 __int64 t;
102
103 GetSystemTimeAsFileTime(&ft);
104 uli.LowPart = ft.dwLowDateTime;
105 uli.HighPart = ft.dwHighDateTime;
106 t = uli.QuadPart; // 100-nanosecond resolution
107 return static_cast<Double_t>(t /= 1E4); // Milliseconds
108#else
109 struct timeval tv;
110 gettimeofday(&tv, nullptr);
111 return static_cast<Double_t>(tv.tv_sec*1E3) + static_cast<Double_t>(tv.tv_usec) / 1E3;
112#endif
113}
#define ClassImp(name)
Definition Rtypes.h:377
Stopwatch object for timing GL work.
Double_t fLastRun
end time (millisec)
TGLStopwatch()
Construct stopwatch object.
void Start()
Start timing.
Double_t fStart
Double_t Lap() const
Return lap time since Start(), in milliseconds.
Double_t fEnd
start time (millisec)
Double_t GetClock(void) const
time of last run (milisec)
Double_t End()
End timing, return total time since Start(), in milliseconds.
virtual ~TGLStopwatch()
Destroy stopwatch object.