xref: /haiku/docs/user/support/StopWatch.dox (revision 002f37b0cca92e4cf72857c72ac95db5a8b09615)
1/*
2 * Copyright 2007 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Documentation written by:
6 *		Niels Sascha Reedijk, niels.reedijk@gmail.com
7 *		John Scipione, jscipione@gmail.com
8 *
9 * Corresponds to:
10 *		headers/os/support/StopWatch.h rev 19972
11 *		src/kits/support/StopWatch.cpp rev 14204
12 */
13
14
15/*!
16	\file StopWatch.h
17	\ingroup support
18	\ingroup libbe
19	\brief Provides the BStopWatch class.
20*/
21
22
23/*!
24	\class BStopWatch
25	\ingroup support
26	\ingroup libbe
27	\brief A simple class used to time events like a stop watch.
28
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.
32
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.
40*/
41
42
43/*!
44	\fn BStopWatch::BStopWatch(const char *name, bool silent)
45	\brief Constructs a BStopWatch object and starts the timer.
46
47	This method creates a new BStopWatch object. As soon as the object is
48	created the timer starts ticking away.
49
50	If you are profiling your code with this class pass \c false to the
51	\a silent parameter to cause the elapsed time information to be
52	streamed to standard output when the object is destroyed.
53
54	\param name The name of the stop watch. You may pass \c NULL to create an
55	       anonymous stop watch.
56	\param silent Pass \c true to suppress time information from streaming to
57	       standard output when the object is destroyed.
58*/
59
60
61/*!
62	\fn BStopWatch::~BStopWatch()
63	\brief Destroys the object stopping the timer.
64
65	If \a silent was set to \c false in the constructor then this method
66	will print elapsed time information to standard output.
67*/
68
69
70/*!
71	\fn void BStopWatch::Resume()
72	\brief Resume the timer from a suspended state.
73
74	\see Suspend()
75*/
76
77
78/*!
79	\fn void BStopWatch::Suspend()
80	\brief Suspend the timer.
81
82	\see Resume()
83*/
84
85
86/*!
87	\fn bigtime_t BStopWatch::Lap()
88	\brief Starts a new timer lap.
89
90	In the current implementation you are unable to actually retrieve the
91	timings of each lap, they are only printed to the standard output when the
92	object is destroyed. This makes the Lap() method only usable when doing
93	some types of profiling.
94
95	\note The current implementation is limited to 10 laps. The value returned
96	      is the time that has passed since the timer was last started (not
97	      the time that has passed since the last lap). Any call to Lap()
98	      beyond the 10th lap will overwrite the last value. Calling Lap()
99	      while the timer is suspended does nothing and returns 0.
100*/
101
102
103/*!
104	\fn bigtime_t BStopWatch::ElapsedTime() const
105	\brief Gets the elapsed time the object has counted.
106
107	\return The elapsed time in microseconds.
108*/
109
110
111/*!
112	\fn void BStopWatch::Reset()
113	\brief Restarts the timer.
114
115	Resets the stop watch clearing the start time and stored laps and
116	restarts the timer.
117*/
118
119
120/*!
121	\fn const char* BStopWatch::Name() const
122	\brief Returns the name of the stop watch.
123
124	If name was set to \c NULL in the constructor this method returns a blank
125	string.
126
127	\return the name of the stop watch set in the constructor.
128*/
129