MCKL
Monte Carlo Kernel Library
Public Types | Public Member Functions | Static Public Member Functions | List of all members
mckl::StopWatchClockAdapter< ClockType > Class Template Reference

StopWatch as an adapter of C++ standard library compatible clock. More...

#include <mckl/utility/stop_watch.hpp>

Public Types

using clock_type = ClockType
 

Public Member Functions

 StopWatchClockAdapter ()
 
std::uint64_t cycles () const
 Return the accumulated cycles. More...
 
double hours () const
 Equivalent to time<double, std::ratio<3600>>() More...
 
double microseconds () const
 Equivalent to time<double, std::micro>() More...
 
double milliseconds () const
 Equivalent to time<double, std::milli>() More...
 
double minutes () const
 Equivalent to time<double, std::ratio<60>>() More...
 
double nanoseconds () const
 Equivalent to time<double, std::nano>() More...
 
void reset ()
 Stop and reset the elapsed time to zero. More...
 
bool running () const
 If the watch is running. More...
 
double seconds () const
 Equivalent to time<double, std::ratio<1>>() More...
 
bool start ()
 Start the watch, no effect if already started. More...
 
bool stop ()
 Stop the watch, no effect if already stopped. More...
 
clock_type::duration const time () const
 Return the accumulated elapsed time in its native format. More...
 
template<typename Rep , typename Period >
Rep time () const
 Return the accumulated elapsed time in specified format. More...
 

Static Public Member Functions

static constexpr bool has_cycles ()
 If cycle counting is supported. More...
 

Detailed Description

template<typename ClockType = std::chrono::high_resolution_clock>
class mckl::StopWatchClockAdapter< ClockType >

StopWatch as an adapter of C++ standard library compatible clock.

Definition at line 166 of file stop_watch.hpp.

Member Typedef Documentation

◆ clock_type

template<typename ClockType = std::chrono::high_resolution_clock>
using mckl::StopWatchClockAdapter< ClockType >::clock_type = ClockType

Definition at line 169 of file stop_watch.hpp.

Constructor & Destructor Documentation

◆ StopWatchClockAdapter()

template<typename ClockType = std::chrono::high_resolution_clock>
mckl::StopWatchClockAdapter< ClockType >::StopWatchClockAdapter ( )
inline

Definition at line 171 of file stop_watch.hpp.

Member Function Documentation

◆ cycles()

template<typename ClockType = std::chrono::high_resolution_clock>
std::uint64_t mckl::StopWatchClockAdapter< ClockType >::cycles ( ) const
inline

Return the accumulated cycles.

Definition at line 248 of file stop_watch.hpp.

◆ has_cycles()

template<typename ClockType = std::chrono::high_resolution_clock>
static constexpr bool mckl::StopWatchClockAdapter< ClockType >::has_cycles ( )
inlinestatic

If cycle counting is supported.

If this function returns true, then cycles() will return the number of accumulated cycles. Otherwise, it will always returns zero.

Definition at line 182 of file stop_watch.hpp.

◆ hours()

template<typename ClockType = std::chrono::high_resolution_clock>
double mckl::StopWatchClockAdapter< ClockType >::hours ( ) const
inline

Equivalent to time<double, std::ratio<3600>>()

Definition at line 278 of file stop_watch.hpp.

◆ microseconds()

template<typename ClockType = std::chrono::high_resolution_clock>
double mckl::StopWatchClockAdapter< ClockType >::microseconds ( ) const
inline

Equivalent to time<double, std::micro>()

Definition at line 266 of file stop_watch.hpp.

◆ milliseconds()

template<typename ClockType = std::chrono::high_resolution_clock>
double mckl::StopWatchClockAdapter< ClockType >::milliseconds ( ) const
inline

Equivalent to time<double, std::milli>()

Definition at line 269 of file stop_watch.hpp.

◆ minutes()

template<typename ClockType = std::chrono::high_resolution_clock>
double mckl::StopWatchClockAdapter< ClockType >::minutes ( ) const
inline

Equivalent to time<double, std::ratio<60>>()

Definition at line 275 of file stop_watch.hpp.

◆ nanoseconds()

template<typename ClockType = std::chrono::high_resolution_clock>
double mckl::StopWatchClockAdapter< ClockType >::nanoseconds ( ) const
inline

Equivalent to time<double, std::nano>()

Definition at line 263 of file stop_watch.hpp.

◆ reset()

template<typename ClockType = std::chrono::high_resolution_clock>
void mckl::StopWatchClockAdapter< ClockType >::reset ( )
inline

Stop and reset the elapsed time to zero.

Definition at line 239 of file stop_watch.hpp.

◆ running()

template<typename ClockType = std::chrono::high_resolution_clock>
bool mckl::StopWatchClockAdapter< ClockType >::running ( ) const
inline

If the watch is running.

If start() has been called and no stop() call since, then it is running, otherwise it is stoped.

Definition at line 196 of file stop_watch.hpp.

◆ seconds()

template<typename ClockType = std::chrono::high_resolution_clock>
double mckl::StopWatchClockAdapter< ClockType >::seconds ( ) const
inline

Equivalent to time<double, std::ratio<1>>()

Definition at line 272 of file stop_watch.hpp.

◆ start()

template<typename ClockType = std::chrono::high_resolution_clock>
bool mckl::StopWatchClockAdapter< ClockType >::start ( )
inline

Start the watch, no effect if already started.

Returns
true if it is started by this call, and the elapsed time will be incremented next time stop() is called. The increment will be relative to the time point of this call. false if it is already started earlier.

Definition at line 204 of file stop_watch.hpp.

◆ stop()

template<typename ClockType = std::chrono::high_resolution_clock>
bool mckl::StopWatchClockAdapter< ClockType >::stop ( )
inline

Stop the watch, no effect if already stopped.

Returns
true if it is stoped by this call, and the elapsed time has been incremented. false if it is already stopped or wasn't started before.

Definition at line 222 of file stop_watch.hpp.

◆ time() [1/2]

template<typename ClockType = std::chrono::high_resolution_clock>
clock_type::duration const mckl::StopWatchClockAdapter< ClockType >::time ( ) const
inline

Return the accumulated elapsed time in its native format.

Definition at line 251 of file stop_watch.hpp.

◆ time() [2/2]

template<typename ClockType = std::chrono::high_resolution_clock>
template<typename Rep , typename Period >
Rep mckl::StopWatchClockAdapter< ClockType >::time ( ) const
inline

Return the accumulated elapsed time in specified format.

Definition at line 255 of file stop_watch.hpp.