NLMISC::CStopWatch Class Reference

#include <stop_watch.h>


Detailed Description

Stopwatch class used for performance measurements and statistics. To measure the duration of a cycle, call stop(), get the results, then call start().
Author:
Olivier Cado

Nevrax France

Date:
2001

Definition at line 48 of file stop_watch.h.

Public Member Functions

void addMeasurement (TTickDuration t)
 Add an external duration (in ticks unit) to the average queue.

void addTime (TTickDuration t)
 Add time (in ticks unit) to the current measurement.

 CStopWatch (uint queueLength=0)
 Constructor. Set a non-zero queueLength for partial average calculation.

TMsDuration getAverageDuration () const
 Average of the duration.

TMsDuration getDuration () const
 Elapsed time in millisecond (call it after stop()).

TMsDuration getPartialAverage () const
 Average duration of the queueLength last durations (using the queueLength argument specified in the constructor).

uint32 measurementNumber () const
 Number of measurements.

void pause ()
 Pause.

void resume ()
 Resume.

void start ()
 Begin measurement.

void stop ()
 End measurement.

TTickDuration sumTicks () const
 Sum of the measured durations (in ticks).


Private Attributes

TTicks _BeginTime
TTickDuration _ElapsedTicks
uint32 _MeasurementNumber
uint _QLength
std::deque< TTickDuration_Queue
TTickDuration _SumTicks


Constructor & Destructor Documentation

NLMISC::CStopWatch::CStopWatch uint  queueLength = 0  ) 
 

Constructor. Set a non-zero queueLength for partial average calculation.

Definition at line 39 of file stop_watch.cpp.

References uint.

00039                                          :
00040         _BeginTime( 0 ),
00041         _ElapsedTicks( 0 ),
00042         _SumTicks( 0 ),
00043         _MeasurementNumber( 0 ),
00044         _Queue(),
00045         _QLength( queueLength )
00046 {}


Member Function Documentation

void NLMISC::CStopWatch::addMeasurement TTickDuration  t  ) 
 

Add an external duration (in ticks unit) to the average queue.

Definition at line 112 of file stop_watch.cpp.

References _MeasurementNumber, _QLength, _Queue, _SumTicks, t, and NLMISC::TTickDuration.

00113 {
00114         // Setup average
00115         _SumTicks += t;
00116         ++_MeasurementNumber;
00117 
00118         // Setup partial average
00119         if ( _QLength != 0 )
00120         {
00121                 _Queue.push_back( t );
00122                 if ( _Queue.size() > _QLength )
00123                 {
00124                         _Queue.pop_front();
00125                 }
00126         }
00127 
00128 }

void NLMISC::CStopWatch::addTime TTickDuration  t  ) 
 

Add time (in ticks unit) to the current measurement.

Definition at line 80 of file stop_watch.cpp.

References _ElapsedTicks, t, and NLMISC::TTickDuration.

00081 {
00082         _ElapsedTicks += t;
00083 }

TMsDuration NLMISC::CStopWatch::getAverageDuration  )  const
 

Average of the duration.

Definition at line 155 of file stop_watch.cpp.

References _MeasurementNumber, _SumTicks, and NLMISC::TMsDuration.

00156 {
00157         return (TMsDuration)(CTime::ticksToSecond( _SumTicks / _MeasurementNumber ) * 1000.0);
00158 }

TMsDuration NLMISC::CStopWatch::getDuration  )  const
 

Elapsed time in millisecond (call it after stop()).

Definition at line 134 of file stop_watch.cpp.

References _ElapsedTicks, and NLMISC::TMsDuration.

00135 {
00136         return (TMsDuration)(CTime::ticksToSecond( _ElapsedTicks ) * 1000.0);
00137 }

TMsDuration NLMISC::CStopWatch::getPartialAverage  )  const
 

Average duration of the queueLength last durations (using the queueLength argument specified in the constructor).

Definition at line 143 of file stop_watch.cpp.

References _Queue, and NLMISC::TMsDuration.

00144 {
00145         if (_Queue.size() == 0)
00146                 return (TMsDuration)0;
00147         else
00148                 return (TMsDuration)(CTime::ticksToSecond( accumulate( _Queue.begin(), _Queue.end(), 0 ) / _Queue.size() ) * 1000.0);
00149 }

uint32 NLMISC::CStopWatch::measurementNumber  )  const [inline]
 

Number of measurements.

Definition at line 92 of file stop_watch.h.

References _MeasurementNumber, and uint32.

00092 { return _MeasurementNumber; }

void NLMISC::CStopWatch::pause  ) 
 

Pause.

Definition at line 62 of file stop_watch.cpp.

References _ElapsedTicks, and NLMISC::TTickDuration.

00063 {
00064         _ElapsedTicks += (TTickDuration)(CTime::getPerformanceTime() - _BeginTime);
00065 }

void NLMISC::CStopWatch::resume  ) 
 

Resume.

Definition at line 71 of file stop_watch.cpp.

00072 {
00073         _BeginTime = CTime::getPerformanceTime();
00074 }

void NLMISC::CStopWatch::start  ) 
 

Begin measurement.

Definition at line 52 of file stop_watch.cpp.

References _ElapsedTicks.

00053 {
00054         _BeginTime = CTime::getPerformanceTime();
00055         _ElapsedTicks = 0;
00056 }

void NLMISC::CStopWatch::stop  ) 
 

End measurement.

Definition at line 89 of file stop_watch.cpp.

References _ElapsedTicks, _MeasurementNumber, _QLength, _Queue, _SumTicks, and NLMISC::TTickDuration.

00090 {
00091         _ElapsedTicks += (TTickDuration)(CTime::getPerformanceTime() - _BeginTime);
00092 
00093         // Setup average
00094         _SumTicks += _ElapsedTicks;
00095         ++_MeasurementNumber;
00096 
00097         // Setup partial average
00098         if ( _QLength != 0 )
00099         {
00100                 _Queue.push_back( _ElapsedTicks );
00101                 if ( _Queue.size() > _QLength )
00102                 {
00103                         _Queue.pop_front();
00104                 }
00105         }
00106 }

TTickDuration NLMISC::CStopWatch::sumTicks  )  const [inline]
 

Sum of the measured durations (in ticks).

Definition at line 89 of file stop_watch.h.

References _SumTicks, and NLMISC::TTickDuration.

00089 { return _SumTicks; }


Field Documentation

TTicks NLMISC::CStopWatch::_BeginTime [private]
 

Definition at line 96 of file stop_watch.h.

TTickDuration NLMISC::CStopWatch::_ElapsedTicks [private]
 

Definition at line 97 of file stop_watch.h.

Referenced by addTime(), getDuration(), pause(), start(), and stop().

uint32 NLMISC::CStopWatch::_MeasurementNumber [private]
 

Definition at line 100 of file stop_watch.h.

Referenced by addMeasurement(), getAverageDuration(), measurementNumber(), and stop().

uint NLMISC::CStopWatch::_QLength [private]
 

Definition at line 103 of file stop_watch.h.

Referenced by addMeasurement(), and stop().

std::deque<TTickDuration> NLMISC::CStopWatch::_Queue [private]
 

Definition at line 102 of file stop_watch.h.

Referenced by addMeasurement(), getPartialAverage(), and stop().

TTickDuration NLMISC::CStopWatch::_SumTicks [private]
 

Definition at line 99 of file stop_watch.h.

Referenced by addMeasurement(), getAverageDuration(), stop(), and sumTicks().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 13:35:13 2004 for NeL by doxygen 1.3.6