Thea
Public Member Functions | List of all members
Stopwatch Class Reference

Accurately measure durations and framerates. More...

#include <Stopwatch.hpp>

Public Member Functions

void after (std::string const &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. More...
 
uint64 elapsedCycles () const
 The elapsed cycle time between tick() and tock(). More...
 
double elapsedTime () const
 Amount of time between the most recent tick() and tock() calls. More...
 
double fps () const
 Get the number of times tick() was called per wall-clock second. More...
 
void reset ()
 Reset the start time used by after() and the smoothed average measures. More...
 
double smoothElapsedTime () const
 Time-smoothed value that is stable to the nearest 1%. More...
 
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. More...
 
 Stopwatch (std::string const &name="Stopwatch")
 Constructor. More...
 
void tick ()
 Begin a timing operation. More...
 
void tock ()
 End a timing operation. More...
 

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();
  printf("%f\n", sw.smoothFPS());

Example 2: For profiling pieces of a sequence:

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

Derived from the G3D library: http://g3d.sourceforge.net

Definition at line 59 of file Stopwatch.hpp.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 35 of file Stopwatch.cpp.

Member Function Documentation

void after ( std::string const &  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.

Definition at line 147 of file Stopwatch.cpp.

uint64 elapsedCycles ( ) const

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.

Definition at line 121 of file Stopwatch.hpp.

double elapsedTime ( ) const

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

0 if tick() has never been called.

Definition at line 103 of file Stopwatch.hpp.

double fps ( ) const

Get the number of times tick() was called per wall-clock second.

If tick() is called once every frame, this measures frames-per-second.

Definition at line 130 of file Stopwatch.hpp.

void reset ( )

Reset the start time used by after() and the smoothed average measures.

Definition at line 140 of file Stopwatch.cpp.

double smoothElapsedTime ( ) const

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.

Definition at line 112 of file Stopwatch.hpp.

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.

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

Definition at line 139 of file Stopwatch.hpp.

void tick ( )

Begin a timing operation.

Definition at line 60 of file Stopwatch.cpp.

void tock ( )

End a timing operation.

Definition at line 73 of file Stopwatch.cpp.


The documentation for this class was generated from the following files: