BDE 4.14.0 Production release
|
Typedefs | |
typedef bsls::Stopwatch | bsls_Stopwatch |
This alias is defined for backward compatibility. | |
Provide access to user, system, and wall times of current process.
This component provides a class, bsls::Stopwatch
, that implements real-time (system clock) interval timers for the system, user, and wall times of the current process. A bsls::Stopwatch
object can accumulate the above values from multiple runs and always presents only the final total (zero if never started or reset to the initial state).
A bsls::Stopwatch
object returns its elapsed time intervals in seconds as double
values. The precision is given by that of the bsls::TimeUtil
component, and, as such, strives to be as high as possible. Monotonic behavior is platform-dependent, however, as are accuracy and useful precision. The user is advised to determine the actual performance on each platform of interest. In general, it is better to avoid stopping and restarting the stopwatch too often (e.g., inside a loop). It is better to measure the overhead of the loop separately and subtract that time from the over-all time interval.
bsls::Stopwatch
may be slow or inconsistent on some Windows machines. See the Accuracy and Precision
section of bsls_timeutil.h
.
The following snippets of code illustrate basic use of a bsls::Stopwatch
object. First we create a stopwatch and note that the accumulated times are all initially 0.0:
Next we start the stopwatch such that it does not accumulate system or user times. Note that a stopwatch always accumulates wall time (i.e., as long as it is in the RUNNING state):
Now stop the stopwatch and restart it so as to accumulate system and user times (i.e., by passing true
to the start
method):
Finally, we reset the stopwatch, which both puts it into the STOPPED state and resets all accumulated times back to their initial state (i.e., 0.0):
typedef bsls::Stopwatch bsls_Stopwatch |