Support Forum       Library Source       SourceForge Page       G3D Web Page     
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | List of all members
G3D::Stopwatch Class Reference

Accurately measure durations and framerates. More...

Public Member Functions

 Stopwatch (const std::string &name="Stopwatch")
 
void after (const std::string &s="")
 Call after an operation has completed, with the name of the operation, to print a debug message listing the time since the previous after() call.
 
uint64 elapsedCycles () const
 The elapsed cycle time between tick and tock.
 
RealTime elapsedTime () const
 Amount of time between the most recent tick and tock calls.
 
bool enabled () const
 A stopwatch only prints output when enabled.
 
double FPS () const
 Returns the number of times that tick was called per wall-clock second; e.g.
 
void reset ()
 Reset the start time used by after() and the emwa value.
 
void setEnabled (bool e)
 
RealTime smoothElapsedTime () const
 Time-smoothed value that is stable to the nearest 1%.
 
double smoothFPS () const
 Time-smoothed value of fps that is stable to the nearest integer for fps > 10 and to the first decimal place for fps <= 10.
 
void tick ()
 Call at the beginning of the period that you want timed.
 
void tock ()
 Call at the end of the period that you want timed.
 

Detailed Description

Accurately measure durations and framerates.

Example 1: For profiling code in the context of a rendering loop:

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

Example 2: For profiling pieces of a sequence:

  Stopwatch sw;
  slowOperation();
  sw.after("slowOperation");
  kdTree.balance();
  sw.after("Balance tree");
 

Constructor & Destructor Documentation

G3D::Stopwatch::Stopwatch ( const std::string name = "Stopwatch")

Member Function Documentation

void G3D::Stopwatch::after ( const std::string s = "")

Call after an operation has completed, with the name of the operation, to print a debug message listing the time since the previous after() call.

Does nothing if the stopwatch is disabled.

uint64 G3D::Stopwatch::elapsedCycles ( ) const
inline

The elapsed cycle time between tick and tock.

An attempt is made to factor out all tick/tock overhead, so that back-to-back calls should return zero. Unreliable on non-x86 platforms.

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

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

0 if tick has never been called.

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

A stopwatch only prints output when enabled.

double G3D::Stopwatch::FPS ( ) const
inline

Returns the number of times that tick was called per wall-clock second; e.g.

frames-per-second.

void G3D::Stopwatch::reset ( )

Reset the start time used by after() and the emwa value.

void G3D::Stopwatch::setEnabled ( bool  e)
inline
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.

double G3D::Stopwatch::smoothFPS ( ) const
inline

Time-smoothed value of fps that is stable to the nearest integer for fps > 10 and to the first decimal place for fps <= 10.

This is useful if you are displaying the frame rate in real-time and want a stable (readable) number.

void G3D::Stopwatch::tick ( )

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

void G3D::Stopwatch::tock ( )

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


documentation generated on Sat Jan 12 2013 22:49:57 using doxygen 1.8.2