Gazebo Math

API Reference

8.0.0
Stopwatch Class Reference

The Stopwatch keeps track of time spent in the run state, accessed through ElapsedRunTime(), and time spent in the stop state, accessed through ElapsedStopTime(). Elapsed run time starts accumulating after the first call to Start(). Elapsed stop time starts accumulation after Start() has been called followed by Stop(). The stopwatch can be reset with the Reset() function. More...

#include <gz/math/Stopwatch.hh>

Public Member Functions

 Stopwatch ()
 Constructor.
 
std::chrono::steady_clock::duration ElapsedRunTime () const
 Get the amount of time that the stop watch has been running. This is the total amount of run time, spannning all start and stop calls. The Reset function or passing true to the Start function will reset this value.
 
std::chrono::steady_clock::duration ElapsedStopTime () const
 Get the amount of time that the stop watch has been stopped. This is the total amount of stop time, spannning all start and stop calls. The Reset function or passing true to the Start function will reset this value.
 
bool operator!= (const Stopwatch &_watch) const
 Inequality operator.
 
bool operator== (const Stopwatch &_watch) const
 Equality operator.
 
void Reset ()
 Reset the stopwatch. This resets the start time, stop time, elapsed duration and elapsed stop duration.
 
bool Running () const
 Get whether the stopwatch is running.
 
bool Start (const bool _reset=false)
 Start the stopwatch.
 
std::chrono::steady_clock::time_point StartTime () const
 Get the time when the stopwatch was started.
 
bool Stop ()
 Stop the stopwatch.
 
std::chrono::steady_clock::time_point StopTime () const
 Get the time when the stopwatch was last stopped.
 

Detailed Description

The Stopwatch keeps track of time spent in the run state, accessed through ElapsedRunTime(), and time spent in the stop state, accessed through ElapsedStopTime(). Elapsed run time starts accumulating after the first call to Start(). Elapsed stop time starts accumulation after Start() has been called followed by Stop(). The stopwatch can be reset with the Reset() function.

Example usage

watch.Start();
// do something...
std::cout << "Elapsed time is "
<< std::chrono::duration_cast<std::chrono::milliseconds>(
timeSys.ElapsedRunTime()).count() << " ms\n";
watch.Stop();

Constructor & Destructor Documentation

◆ Stopwatch()

Stopwatch ( )

Constructor.

Member Function Documentation

◆ ElapsedRunTime()

std::chrono::steady_clock::duration ElapsedRunTime ( ) const

Get the amount of time that the stop watch has been running. This is the total amount of run time, spannning all start and stop calls. The Reset function or passing true to the Start function will reset this value.

Returns
Total amount of elapsed run time.

◆ ElapsedStopTime()

std::chrono::steady_clock::duration ElapsedStopTime ( ) const

Get the amount of time that the stop watch has been stopped. This is the total amount of stop time, spannning all start and stop calls. The Reset function or passing true to the Start function will reset this value.

Returns
Total amount of elapsed stop time.

◆ operator!=()

bool operator!= ( const Stopwatch _watch) const

Inequality operator.

Parameters
[in]_watchThe watch to compare.
Returns
True if this watch does not equal the provided watch.

◆ operator==()

bool operator== ( const Stopwatch _watch) const

Equality operator.

Parameters
[in]_watchThe watch to compare.
Returns
True if this watch equals the provided watch.

◆ Reset()

void Reset ( )

Reset the stopwatch. This resets the start time, stop time, elapsed duration and elapsed stop duration.

◆ Running()

bool Running ( ) const

Get whether the stopwatch is running.

Returns
True if the stopwatch is running.

◆ Start()

bool Start ( const bool  _reset = false)

Start the stopwatch.

Parameters
[in]_resetIf true the stopwatch is reset first.
Returns
True if the the stopwatch was started. This will return false if the stopwatch was already running.

◆ StartTime()

std::chrono::steady_clock::time_point StartTime ( ) const

Get the time when the stopwatch was started.

Returns
The time when stopwatch was started, or std::chrono::steady_clock::time_point::min() if the stopwatch has not been started.

◆ Stop()

bool Stop ( )

Stop the stopwatch.

Returns
True if the stopwatch was stopped. This will return false if the stopwatch is not running.

◆ StopTime()

std::chrono::steady_clock::time_point StopTime ( ) const

Get the time when the stopwatch was last stopped.

Returns
The time when stopwatch was last stopped, or std::chrono::steady_clock::time_point::min() if the stopwatch has never been stopped.

The documentation for this class was generated from the following file: