qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::ScopedTimer Class Reference

Utility for measuring code block execution time. More...

#include <timestamp.h>

Public Types

using TimerCallback = std::function<void(Duration)>

Public Member Functions

 ScopedTimer (TimerCallback callback)
 Constructs a timer with a callback.
 ~ScopedTimer ()
 Destructor that invokes callback with elapsed time.
Duration stop ()
 Stops the timer and invokes callback if active.
void restart ()
 Restarts the timer.
Duration elapsed () const
 Gets elapsed time without stopping timer.
 ScopedTimer (const ScopedTimer &)=delete
ScopedTimeroperator= (const ScopedTimer &)=delete
 ScopedTimer (ScopedTimer &&)=delete
ScopedTimeroperator= (ScopedTimer &&)=delete

Detailed Description

Utility for measuring code block execution time.

Measures elapsed time between construction and destruction, optionally invoking a callback with the measured duration.

Constructor & Destructor Documentation

◆ ScopedTimer()

qb::ScopedTimer::ScopedTimer ( TimerCallback callback)
inlineexplicit

Constructs a timer with a callback.

Parameters
callbackFunction to call with measured duration when timer is destroyed

Member Function Documentation

◆ stop()

Duration qb::ScopedTimer::stop ( )
inline

Stops the timer and invokes callback if active.

Returns
Measured duration

◆ elapsed()

Duration qb::ScopedTimer::elapsed ( ) const
inline

Gets elapsed time without stopping timer.

Returns
Current elapsed duration