[#BloombergLP-bsls-Stopwatch]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bsls.adoc[bsls]::Stopwatch
:relfileprefix: ../../
:mrdocs:

The `class` provides an accumulator for the system, user, and wall times of the current process&period; A stopwatch can be in either the STOPPED (initial) state or the RUNNING state&period; It potentially tracks three values&colon; the accumulated system time, the accumulated user time, and the accumulated wall time (all in seconds and all initially set to zero)&period; Whether or not system and user times are accumulated is conditional on how the stopwatch is started (see the `start` method)&period; While in the RUNNING state, a stopwatch accumulates the above values and it retains the values if put into the STOPPED state (unless `reset` is called)&period; The accumulated times can be accessed at any time and in either state (RUNNING or STOPPED)&period;

== Synopsis

Declared in `&lt;bsls&lowbar;stopwatch&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class Stopwatch;
----

== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bsls/Stopwatch/2constructor-05.adoc[`Stopwatch`]         [.small]#[constructor]#
| Constructors
| xref:BloombergLP/bsls/Stopwatch/2destructor.adoc[`&#126;Stopwatch`] [.small]#[destructor]#
| Destroy this stopwatch&period; Note that this method&apos;s definition is compiler generated&period;
| xref:BloombergLP/bsls/Stopwatch/accumulatedSystemTime.adoc[`accumulatedSystemTime`] 
| Return the total (instantaneous and quiescent) elapsed system time (in seconds) accumulated by this stopwatch, or 0 if the collection of CPU times is disabled&period;
| xref:BloombergLP/bsls/Stopwatch/accumulatedTimes.adoc[`accumulatedTimes`] 
| Load into the specified `systemTime`, `userTime` and `wallTime` the total (instantaneous and quiescent) elapsed system, user, and wall times (all in seconds) accumulated by this stopwatch&period; Note that this method attempts to retrieve all of the values at the same time (atomically), if the underlying platform supports it&period;
| xref:BloombergLP/bsls/Stopwatch/accumulatedUserTime.adoc[`accumulatedUserTime`] 
| Return the total (instantaneous and quiescent) elapsed user time (in seconds) accumulated by this stopwatch, or 0 if the collection of CPU times is disabled&period;
| xref:BloombergLP/bsls/Stopwatch/accumulatedWallTime.adoc[`accumulatedWallTime`] 
| Return the total (instantaneous and quiescent) elapsed wall time (in seconds) accumulated by this stopwatch&period;
| xref:BloombergLP/bsls/Stopwatch/elapsedTime.adoc[`elapsedTime`] 
| Return the total (instantaneous and quiescent) elapsed wall time (in seconds) accumulated by this stopwatch&period; Note that this method is equivalent to `accumulatedWallTime`&period;
| xref:BloombergLP/bsls/Stopwatch/isRunning.adoc[`isRunning`] 
| Return `true` if this stopwatch is in the RUNNING state, and `false` otherwise&period;
| xref:BloombergLP/bsls/Stopwatch/reset.adoc[`reset`] 
| Place this stopwatch in the STOPPED state, unconditionally stopping the accumulation of elapsed times, and set the quiescent elapsed times to 0&period;0&period;
| xref:BloombergLP/bsls/Stopwatch/start.adoc[`start`] 
| Place this stopwatch in the RUNNING state and begin accumulating elapsed times if this object was in the STOPPED state&period; Optionally specify a `collectCpuTimes` flag indicating whether CPU times should be collected&period; If `collectCpuTimes` is not specified, then CPU times are _not_ collected&period; Note that the instantaneous total elapsed times are available from the RUNNING state&period; Also note that disabling collection of CPU times will result in fewer systems calls and therefore faster measurements&period; Also note that `collectCpuTimes` may be expressed using the one of the class level constants `k&lowbar;COLLECT&lowbar;WALL&lowbar;TIME&lowbar;ONLY`, and `k&lowbar;COLLECT&lowbar;WALL&lowbar;AND&lowbar;CPU&lowbar;TIMES` for easier immediate understanding of the meaning of the client code&period;
| xref:BloombergLP/bsls/Stopwatch/stop.adoc[`stop`] 
| Place this stopwatch in the STOPPED state, unconditionally stopping the accumulation of elapsed times&period; Note that the quiescent accumulated elapsed times are available while in the STOPPED state&period;
|===


== Static Data Members

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bsls/Stopwatch/k_COLLECT_WALL_AND_CPU_TIMES.adoc[`k&lowbar;COLLECT&lowbar;WALL&lowbar;AND&lowbar;CPU&lowbar;TIMES`] 
| For readability&sol;ease of understanding of code that calls the `start(bool)` method use these constants as arguments&period;
| xref:BloombergLP/bsls/Stopwatch/k_COLLECT_WALL_TIME_ONLY.adoc[`k&lowbar;COLLECT&lowbar;WALL&lowbar;TIME&lowbar;ONLY`] 
| Collect wall time only (not CPU time)&period;
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
