TGLStopwatch.cxx

Go to the documentation of this file.
00001 // @(#)root/gl:$Id: TGLStopwatch.cxx 23087 2008-04-09 14:10:56Z rdm $
00002 // Author:  Richard Maunder  25/05/2005
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TGLStopwatch.h"
00013 #include "TGLIncludes.h"
00014 
00015 #ifdef R__WIN32
00016 #include <Windows.h>  // For GetSystemTimeAsFileTime()
00017 #else
00018 #include <sys/time.h> // For gettimeofday()
00019 #endif
00020 
00021 //////////////////////////////////////////////////////////////////////////
00022 //                                                                      //
00023 // TGLStopwatch                                                         //
00024 //                                                                      //
00025 // Stopwatch object for timing GL work. We do not use the TStopwatch as //
00026 // we need to perform GL flushing to get accurate times + we record     //
00027 // timing overheads here.                                               //
00028 //////////////////////////////////////////////////////////////////////////
00029 
00030 ClassImp(TGLStopwatch);
00031 
00032 //______________________________________________________________________________
00033 TGLStopwatch::TGLStopwatch() : fStart(0), fEnd(0), fLastRun(0)
00034 {
00035    // Construct stopwatch object.
00036 }
00037 
00038 //______________________________________________________________________________
00039 TGLStopwatch::~TGLStopwatch()
00040 {
00041    // Destroy stopwatch object.
00042 }
00043 
00044 //______________________________________________________________________________
00045 void TGLStopwatch::Start()
00046 {
00047    // Start timing.
00048 
00049    fStart   = GetClock();
00050    fEnd     = 0;
00051 }
00052 
00053 // In milliseconds
00054 //______________________________________________________________________________
00055 Double_t TGLStopwatch::Lap() const
00056 {
00057    // Return lap time since Start(), in milliseconds.
00058 
00059    if (fStart == 0)
00060       return 0;
00061    else
00062       return GetClock() - fStart;
00063 }
00064 
00065 // In milliseconds
00066 //______________________________________________________________________________
00067 Double_t TGLStopwatch::End()
00068 {
00069    // End timing, return total time since Start(), in milliseconds.
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    // Get internal clock time, in milliseconds.
00084 
00085 #ifdef R__WIN32
00086    // Use performance counter (system dependent support) if possible
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    // TODO: Portability - check with Rene
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;                        // 100-nanosecond resolution
00107    return static_cast<Double_t>(t /= 1E4);   // Milliseconds
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 }

Generated on Tue Jul 5 14:18:08 2011 for ROOT_528-00b_version by  doxygen 1.5.1