quill
Public Member Functions | List of all members
detail::StopWatch< ClockType > Class Template Reference

A stopwatch utility for measuring elapsed time since construction. More...

#include <StopWatch.h>

Public Member Functions

 StopWatch ()
 Constructor.
 
std::chrono::duration< double > elapsed () const
 Returns the elapsed time since construction. More...
 
template<typename T >
elapsed_as () const
 Returns the elapsed time since construction as the specified duration type. More...
 
void reset ()
 Resets the stopwatch, starting the measurement from the current time.
 

Detailed Description

template<ClockSourceType ClockType>
class detail::StopWatch< ClockType >

A stopwatch utility for measuring elapsed time since construction.

Displays elapsed time as seconds (double) or any specified duration type.

Can use either TSC-based or system clock-based timing, depending on the template parameter ClockType.

Example:

quill::StopWatchTsc swt;
LOG_INFO(logger, "Begin");
std::this_thread::sleep_for(std::chrono::seconds(1));
LOG_INFO(logger, "After 1s, elapsed: {:.6}", swt); // => elapsed: ~1.000000
std::this_thread::sleep_for(std::chrono::milliseconds(500));
LOG_INFO(logger, "After 500ms, elapsed: {}", swt); // => elapsed: ~1.500000

Member Function Documentation

◆ elapsed()

template<ClockSourceType ClockType>
std::chrono::duration<double> detail::StopWatch< ClockType >::elapsed ( ) const
inline

Returns the elapsed time since construction.

Returns
The elapsed time as a std::chrono::duration<double> in seconds.

◆ elapsed_as()

template<ClockSourceType ClockType>
template<typename T >
T detail::StopWatch< ClockType >::elapsed_as ( ) const
inline

Returns the elapsed time since construction as the specified duration type.

Returns
The elapsed time converted to the specified duration type.

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