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
28
29////////////////////////////////////////////////////////////////////////////////
30/// Construct stopwatch object.
31
32TGLStopwatch::TGLStopwatch() : fStart(0), fEnd(0), fLastRun(0)
33{
34}
35
36////////////////////////////////////////////////////////////////////////////////
37/// Destroy stopwatch object.
38
42
43////////////////////////////////////////////////////////////////////////////////
44/// Start timing.
45
47{
48 fStart = GetClock();
49 fEnd = 0;
50}
51
52// In milliseconds
53////////////////////////////////////////////////////////////////////////////////
54/// Return lap time since Start(), in milliseconds.
55
57{
58 if (fStart == 0)
59 return 0;
60 else
61 return GetClock() - fStart;
62}
63
64// In milliseconds
65////////////////////////////////////////////////////////////////////////////////
66/// End timing, return total time since Start(), in milliseconds.
67
69{
70 if (fStart == 0)
71 return 0;
72 if (fEnd == 0) {
73 fEnd = GetClock();
75 }
76 return fLastRun;
77}
78
79////////////////////////////////////////////////////////////////////////////////
80/// Get internal clock time, in milliseconds.
81
83{
84#ifdef R__WIN32
85 // Use performance counter (system dependent support) if possible
86 static LARGE_INTEGER perfFreq;
88
90 LARGE_INTEGER counter;
92 Double_t time = static_cast<Double_t>(counter.QuadPart)*1000.0 /
93 static_cast<Double_t>(perfFreq.QuadPart);
94 return time;
95 }
96
97 // TODO: Portability - check with Rene
100 __int64 t;
101
103 uli.LowPart = ft.dwLowDateTime;
104 uli.HighPart = ft.dwHighDateTime;
105 t = uli.QuadPart; // 100-nanosecond resolution
106 return static_cast<Double_t>(t /= 1E4); // Milliseconds
107#else
108 struct timeval tv;
109 gettimeofday(&tv, nullptr);
110 return static_cast<Double_t>(tv.tv_sec*1E3) + static_cast<Double_t>(tv.tv_usec) / 1E3;
111#endif
112}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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.