DART 6.13.2
Loading...
Searching...
No Matches
dart::common::Stopwatch< UnitType, ClockType > Class Template Referencefinal

Simple stopwatch implementation. More...

#include <Stopwatch.hpp>

Public Member Functions

 Stopwatch (bool start=true)
 Constructor.
 
 ~Stopwatch ()
 Destructor.
 
bool isStarted () const
 Returns whether the stopwatch is started.
 
void start ()
 Starts the stopwatch.
 
void stop ()
 Stops the stopwatch.
 
void reset ()
 Resets the stopwatch.
 
double elapsedS () const
 Returns the elapsed time in seconds.
 
double elapsedMS () const
 Returns the elapsed time in milliseconds.
 
double elapsedUS () const
 Returns the elapsed time in microseconds.
 
double elapsedNS () const
 Returns the elapsed time in nanoseconds.
 
void print (std::ostream &os=std::cout) const
 Prints state of the stopwatch.
 

Private Member Functions

 Stopwatch (const Stopwatch &)=delete
 
 Stopwatch (Stopwatch &&)=delete
 
Stopwatchoperator= (const Stopwatch &)=delete
 
Stopwatchoperator= (Stopwatch &&)=delete
 
UnitType duration () const
 Returns the duration.
 

Private Attributes

ClockType::time_point mStart
 The start time.
 
UnitType mElapsed
 The elapsed time.
 
bool mPaused
 Whether the stopwatch is paused.
 

Friends

template<typename T , typename U >
std::ostream & operator<< (std::ostream &os, const Stopwatch< T, U > &sw)
 Prints state of the stopwatch.
 

Detailed Description

template<typename UnitType, typename ClockType = std::chrono::high_resolution_clock>
class dart::common::Stopwatch< UnitType, ClockType >

Simple stopwatch implementation.

Constructor & Destructor Documentation

◆ Stopwatch() [1/3]

template<typename UnitType , typename ClockType >
dart::common::Stopwatch< UnitType, ClockType >::Stopwatch ( bool  start = true)
explicit

Constructor.

Parameters
[in]start(optional) Whether to start the stopwatch on construction

◆ ~Stopwatch()

template<typename UnitType , typename ClockType >
dart::common::Stopwatch< UnitType, ClockType >::~Stopwatch ( )

Destructor.

◆ Stopwatch() [2/3]

template<typename UnitType , typename ClockType = std::chrono::high_resolution_clock>
dart::common::Stopwatch< UnitType, ClockType >::Stopwatch ( const Stopwatch< UnitType, ClockType > &  )
privatedelete

◆ Stopwatch() [3/3]

template<typename UnitType , typename ClockType = std::chrono::high_resolution_clock>
dart::common::Stopwatch< UnitType, ClockType >::Stopwatch ( Stopwatch< UnitType, ClockType > &&  )
privatedelete

Member Function Documentation

◆ duration()

template<typename UnitType , typename ClockType >
UnitType dart::common::Stopwatch< UnitType, ClockType >::duration ( ) const
private

Returns the duration.

◆ elapsedMS()

template<typename UnitType , typename ClockType >
double dart::common::Stopwatch< UnitType, ClockType >::elapsedMS ( ) const

Returns the elapsed time in milliseconds.

◆ elapsedNS()

template<typename UnitType , typename ClockType >
double dart::common::Stopwatch< UnitType, ClockType >::elapsedNS ( ) const

Returns the elapsed time in nanoseconds.

◆ elapsedS()

template<typename UnitType , typename ClockType >
double dart::common::Stopwatch< UnitType, ClockType >::elapsedS ( ) const

Returns the elapsed time in seconds.

◆ elapsedUS()

template<typename UnitType , typename ClockType >
double dart::common::Stopwatch< UnitType, ClockType >::elapsedUS ( ) const

Returns the elapsed time in microseconds.

◆ isStarted()

template<typename UnitType , typename ClockType >
bool dart::common::Stopwatch< UnitType, ClockType >::isStarted ( ) const

Returns whether the stopwatch is started.

◆ operator=() [1/2]

template<typename UnitType , typename ClockType = std::chrono::high_resolution_clock>
Stopwatch & dart::common::Stopwatch< UnitType, ClockType >::operator= ( const Stopwatch< UnitType, ClockType > &  )
privatedelete

◆ operator=() [2/2]

template<typename UnitType , typename ClockType = std::chrono::high_resolution_clock>
Stopwatch & dart::common::Stopwatch< UnitType, ClockType >::operator= ( Stopwatch< UnitType, ClockType > &&  )
privatedelete

◆ print()

template<typename UnitType , typename ClockType >
void dart::common::Stopwatch< UnitType, ClockType >::print ( std::ostream &  os = std::cout) const

Prints state of the stopwatch.

◆ reset()

template<typename UnitType , typename ClockType >
void dart::common::Stopwatch< UnitType, ClockType >::reset ( )

Resets the stopwatch.

Sets the start time to current time and the accumulated elasped time to zero.

◆ start()

template<typename UnitType , typename ClockType >
void dart::common::Stopwatch< UnitType, ClockType >::start ( )

Starts the stopwatch.

◆ stop()

template<typename UnitType , typename ClockType >
void dart::common::Stopwatch< UnitType, ClockType >::stop ( )

Stops the stopwatch.

Friends And Related Symbol Documentation

◆ operator<<

template<typename UnitType , typename ClockType = std::chrono::high_resolution_clock>
template<typename T , typename U >
std::ostream & operator<< ( std::ostream &  os,
const Stopwatch< T, U > &  sw 
)
friend

Prints state of the stopwatch.

Member Data Documentation

◆ mElapsed

template<typename UnitType , typename ClockType = std::chrono::high_resolution_clock>
UnitType dart::common::Stopwatch< UnitType, ClockType >::mElapsed
private

The elapsed time.

◆ mPaused

template<typename UnitType , typename ClockType = std::chrono::high_resolution_clock>
bool dart::common::Stopwatch< UnitType, ClockType >::mPaused
private

Whether the stopwatch is paused.

◆ mStart

template<typename UnitType , typename ClockType = std::chrono::high_resolution_clock>
ClockType::time_point dart::common::Stopwatch< UnitType, ClockType >::mStart
private

The start time.