Support Forum       G3D Web Page     
Public Member Functions | List of all members
G3D::Stopwatch Class Reference

Provides accurate measurement of durations. More...

Public Member Functions

 Stopwatch (const String &name="Stopwatch")
 
template<class Duration = chrono::nanoseconds>
Duration elapsedDuration () const
 Provides the elapsed time as a std::chrono::duration. More...
 
RealTime elapsedTime () const
 Amount of time between the most recent tick and tock calls. More...
 
bool enabled () const
 /deprecated Use ContinuousStopwatch More...
 
void printElapsedTime (const String &s=String())
 /deprcated Use ContinuousStopwatch More...
 
void reset ()
 /deprecated Use ContinuousStopwatch More...
 
void setEnabled (bool e)
 /deprecated Use ContinuousStopwatch More...
 
template<class Duration = chrono::nanoseconds>
Duration smoothElapsedDuration () const
 Provides the smooth elapsed time as a std::chrono::duration. More...
 
RealTime smoothElapsedTime () const
 Time-smoothed value that is stable to the nearest 1%. More...
 
void tick ()
 Call at the beginning of the period that you want timed. More...
 
void tock ()
 Call at the end of the period that you want timed. More...
 

Detailed Description

Provides accurate measurement of durations.

Example 1: For profiling code

    Stopwatch sw;
    sw.tick();
    ...timed code...
    sw.tock();
    screenPrintf("%f\n", sw.elapsedTime());

Example 2: For profiling sequences of code

    Stopwatch sw;
    sw.setEnabled(true);
    slowOperation();
    sw.printElapsedTime("slowOperation");
    kdTree.balance();
    sw.printElapsedTime("Balance tree");
See also
ContinuousStopwatch

Constructor & Destructor Documentation

◆ Stopwatch()

G3D::Stopwatch::Stopwatch ( const String name = "Stopwatch")

Member Function Documentation

◆ elapsedDuration()

template<class Duration = chrono::nanoseconds>
Duration G3D::Stopwatch::elapsedDuration ( ) const
inline

Provides the elapsed time as a std::chrono::duration.

Use this if you want resolution smaller than seconds before rounding.

◆ elapsedTime()

RealTime G3D::Stopwatch::elapsedTime ( ) const
inline

Amount of time between the most recent tick and tock calls.

0 if tick has never been called.

◆ enabled()

bool G3D::Stopwatch::enabled ( ) const
inline

/deprecated Use ContinuousStopwatch

◆ printElapsedTime()

void G3D::Stopwatch::printElapsedTime ( const String s = String())
inline

/deprcated Use ContinuousStopwatch

◆ reset()

void G3D::Stopwatch::reset ( )
inline

/deprecated Use ContinuousStopwatch

◆ setEnabled()

void G3D::Stopwatch::setEnabled ( bool  e)
inline

/deprecated Use ContinuousStopwatch

◆ smoothElapsedDuration()

template<class Duration = chrono::nanoseconds>
Duration G3D::Stopwatch::smoothElapsedDuration ( ) const
inline

Provides the smooth elapsed time as a std::chrono::duration.

Use this if you want resolution smaller than seconds before rounding.

◆ smoothElapsedTime()

RealTime G3D::Stopwatch::smoothElapsedTime ( ) const
inline

Time-smoothed value that is stable to the nearest 1%.

This is useful if you are displaying elapsed time in real-time and want a stable number.

◆ tick()

void G3D::Stopwatch::tick ( )

Call at the beginning of the period that you want timed.

◆ tock()

void G3D::Stopwatch::tock ( )

Call at the end of the period that you want timed.


documentation generated on Wed Nov 24 2021 08:02:00 using doxygen 1.8.15