A simple class used to time events like a stop watch. More...
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. | |
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.
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.
name | The name of the stop watch. You may pass NULL to create an anonymous stop watch. |
silent | Pass true to suppress time information from streaming to standard output when the object is destroyed. |
|
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.
bigtime_t BStopWatch::ElapsedTime | ( | ) | const |
Gets the elapsed time the object has counted.
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.
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.
void BStopWatch::Reset | ( | ) |
Restarts the timer.
Resets the stop watch clearing the start time and stored laps and restarts the timer.
void BStopWatch::Resume | ( | ) |
void BStopWatch::Suspend | ( | ) |