2 * Copyright 2007-2014 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Documentation written by:
6 * Niels Sascha Reedijk, niels.reedijk@gmail.com
7 * John Scipione, jscipione@gmail.com
10 * headers/os/support/StopWatch.h rev 19972
11 * src/kits/support/StopWatch.cpp rev 14204
19 \brief Provides the BStopWatch class.
27 \brief A simple class used to time events like a stop watch.
29 The interface of this class is designed to behave like a physical
30 stop watch. It is useful for debugging parts of your code acting as a
31 quick and dirty profiler.
33 To use this class first create a BStopWatch object, this starts the timer
34 going. You may call Suspend() and Resume() to start and stop the stop
35 watch. Call ElapsedTime() to get the current timer count at any time. You
36 may call Lap() to start a new lap (up to 10 laps are supported) or call
37 Reset() to reset the timer back to 0 clearing all lap info. When the
38 object is destroyed the timing information is streamed to standard out
39 unless you set the \a silent parameter to \c true in the constructor.
46 \fn BStopWatch::BStopWatch(const char* name, bool silent)
47 \brief Constructs a BStopWatch object and starts the timer.
49 This method creates a new BStopWatch object. As soon as the object is
50 created the timer starts ticking away.
52 If you are profiling your code with this class pass \c false to the
53 \a silent parameter to cause the elapsed time information to be
54 streamed to standard output when the object is destroyed.
56 \param name The name of the stop watch. You may pass \c NULL to create an
58 \param silent Pass \c true to suppress time information from streaming to
59 standard output when the object is destroyed.
66 \fn BStopWatch::~BStopWatch()
67 \brief Destroys the object stopping the timer.
69 If \a silent was set to \c false in the constructor then this method
70 will print elapsed time information to standard output.
77 \fn void BStopWatch::Resume()
78 \brief Resume the timer from a suspended state.
87 \fn void BStopWatch::Suspend()
88 \brief Suspend the timer.
97 \fn bigtime_t BStopWatch::Lap()
98 \brief Starts a new timer lap.
100 In the current implementation you are unable to actually retrieve the
101 timings of each lap, they are only printed to the standard output when the
102 object is destroyed. This makes the Lap() method only usable when doing
103 some types of profiling.
105 \note The current implementation is limited to 10 laps. The value returned
106 is the time that has passed since the timer was last started (not
107 the time that has passed since the last lap). Any call to Lap()
108 beyond the 10th lap will overwrite the last value. Calling Lap()
109 while the timer is suspended does nothing and returns 0.
116 \fn bigtime_t BStopWatch::ElapsedTime() const
117 \brief Gets the elapsed time the object has counted.
119 \return The elapsed time in microseconds.
126 \fn void BStopWatch::Reset()
127 \brief Restarts the timer.
129 Resets the stop watch clearing the start time and stored laps and
137 \fn const char* BStopWatch::Name() const
138 \brief Returns the name of the stop watch.
140 If name was set to \c NULL in the constructor this method returns a blank
143 \return the name of the stop watch set in the constructor.