Public Member Functions
BStopWatch Class Reference

A simple class used to time events like a stop watch. More...

List of all members.

Public Member Functions

 BStopWatch (const char *name, bool silent=false)
 Constructs a BStopWatch object and starts the timer.
virtual ~BStopWatch ()
 Destroys the object stopping the timer.
bigtime_t ElapsedTime () const
 Gets the elapsed time the object has counted.
bigtime_t Lap ()
 Starts a new timer lap.
const char * Name () const
 Returns the name of the stop watch.
void Reset ()
 Restarts the timer.
void Resume ()
 Resume the timer from a suspended state.
void Suspend ()
 Suspend the timer.

Detailed Description

A simple class used to time events like a stop watch.

The interface of this class is designed to behave like a physical stop watch. It is useful for debugging parts of your code acting as a quick and dirty profiler.

To use this class first create a BStopWatch object, this starts the timer going. You may call Suspend() and Resume() to start and stop the stop watch. Call ElapsedTime() to get the current timer count at any time. You may call Lap() to start a new lap (up to 10 laps are supported) or call Reset() to reset the timer back to 0 clearing all lap info. When the object is destroyed the timing information is streamed to standard out unless you set the silent parameter to true in the constructor.


Constructor & Destructor Documentation

BStopWatch::BStopWatch ( const char *  name,
bool  silent = false 
)

Constructs a BStopWatch object and starts the timer.

This method creates a new BStopWatch object. As soon as the object is created the timer starts ticking away.

If you are profiling your code with this class pass false to the silent parameter to cause the elapsed time information to be streamed to standard output when the object is destroyed.

Parameters:
nameThe name of the stop watch. You may pass NULL to create an anonymous stop watch.
silentPass true to suppress time information from streaming to standard output when the object is destroyed.
BStopWatch::~BStopWatch ( ) [virtual]

Destroys the object stopping the timer.

If silent was set to false in the constructor then this method will print elapsed time information to standard output.


Member Function Documentation

bigtime_t BStopWatch::ElapsedTime ( ) const

Gets the elapsed time the object has counted.

Returns:
The elapsed time in microseconds.
bigtime_t BStopWatch::Lap ( )

Starts a new timer lap.

In the current implementation you are unable to actually retrieve the timings of each lap, they are only printed to the standard output when the object is destroyed. This makes the Lap() method only usable when doing some types of profiling.

Note:
The current implementation is limited to 10 laps. The value returned is the time that has passed since the timer was last started (not the time that has passed since the last lap). Any call to Lap() beyond the 10th lap will overwrite the last value. Calling Lap() while the timer is suspended does nothing and returns 0.
const char * BStopWatch::Name ( ) const

Returns the name of the stop watch.

If name was set to NULL in the constructor this method returns a blank string.

Returns:
the name of the stop watch set in the constructor.
void BStopWatch::Reset ( )

Restarts the timer.

Resets the stop watch clearing the start time and stored laps and restarts the timer.

void BStopWatch::Resume ( )

Resume the timer from a suspended state.

See also:
Suspend()
void BStopWatch::Suspend ( )

Suspend the timer.

See also:
Resume()

The Haiku Book pre-R1 - BStopWatch Class Reference
Generated on Mon May 20 2013 by Doxygen 1.7.5.1