MXVK Vulkan Framework 0.24.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
StopWatch< T > Class Template Reference

RAII stopwatch using a selectable clock policy. More...

#include <mxvk/include/mxvk/mxvk_stopwatch.hpp>

Public Member Functions

void Echo (std::string_view name) const
 Print the interval recorded by the clock policy.
StopWatchoperator= (const StopWatch &)=delete
 Stopwatches cannot be copy-assigned.
StopWatchoperator= (StopWatch &&)=delete
 Stopwatches cannot be move-assigned.
void Start (std::string_view name)
 Start a new timed interval.
void Stop ()
 Stop the current interval and print its duration.
 StopWatch (const StopWatch &)=delete
 Stopwatches cannot be copied.
 StopWatch (std::string_view name)
 Construct and immediately start a stopwatch.
 StopWatch (StopWatch &&)=delete
 Stopwatches cannot be moved.
unsigned long TimePassed () const
 Query the time elapsed since the most recent Start().
 ~StopWatch ()
 Stop and print the timer if it is still running.

Detailed Description

template<ClockPolicy T>
class StopWatch< T >

RAII stopwatch using a selectable clock policy.

Construction starts the timer immediately. Stop() prints the result and is safe to call more than once. If the stopwatch is still running when it is destroyed, the destructor stops it and prints the result automatically.

Template Parameters
TClock policy satisfying ClockPolicy.

\par Note:
The stopwatch stores its name as a std::string_view. The referenced string must remain valid for the lifetime of the stopwatch.

Definition at line 133 of file mxvk_stopwatch.hpp.

Constructor & Destructor Documentation

◆ StopWatch() [1/3]

template<ClockPolicy T>
StopWatch< T >::StopWatch ( std::string_view name)
inlineexplicit

Construct and immediately start a stopwatch.

Parameters
nameDescriptive name printed with the timing result.

Definition at line 139 of file mxvk_stopwatch.hpp.

139 : time_name(name) {
140 Start(name);
141 }
RAII stopwatch using a selectable clock policy.
void Start(std::string_view name)
Start a new timed interval.

◆ ~StopWatch()

template<ClockPolicy T>
StopWatch< T >::~StopWatch ( )
inline

Stop and print the timer if it is still running.

Definition at line 144 of file mxvk_stopwatch.hpp.

144 {
145 if (!m_stopped) {
146 Stop();
147 }
148 }
void Stop()
Stop the current interval and print its duration.

◆ StopWatch() [2/3]

template<ClockPolicy T>
StopWatch< T >::StopWatch ( const StopWatch< T > & )
delete

Stopwatches cannot be copied.

◆ StopWatch() [3/3]

template<ClockPolicy T>
StopWatch< T >::StopWatch ( StopWatch< T > && )
delete

Stopwatches cannot be moved.

Member Function Documentation

◆ Echo()

template<ClockPolicy T>
void StopWatch< T >::Echo ( std::string_view name) const
inline

Print the interval recorded by the clock policy.

Parameters
nameDescriptive name shown with the timing result.

Definition at line 188 of file mxvk_stopwatch.hpp.

188 {
189 clock_interface.echo(name);
190 }

◆ operator=() [1/2]

template<ClockPolicy T>
StopWatch & StopWatch< T >::operator= ( const StopWatch< T > & )
delete

Stopwatches cannot be copy-assigned.

◆ operator=() [2/2]

template<ClockPolicy T>
StopWatch & StopWatch< T >::operator= ( StopWatch< T > && )
delete

Stopwatches cannot be move-assigned.

◆ Start()

template<ClockPolicy T>
void StopWatch< T >::Start ( std::string_view name)
inline

Start a new timed interval.

Parameters
nameDescriptive name printed with the timing result.

Calling this function restarts the stopwatch and replaces its name.

Definition at line 165 of file mxvk_stopwatch.hpp.

165 {
166 time_name = name;
167 m_stopped = false;
168 clock_interface.start();
169 }

◆ Stop()

template<ClockPolicy T>
void StopWatch< T >::Stop ( )
inline

Stop the current interval and print its duration.

Repeated calls have no effect until Start() begins another interval.

Definition at line 176 of file mxvk_stopwatch.hpp.

176 {
177 if (m_stopped)
178 return;
179 clock_interface.stop();
180 Echo(time_name);
181 m_stopped = true;
182 }
void Echo(std::string_view name) const
Print the interval recorded by the clock policy.

◆ TimePassed()

template<ClockPolicy T>
unsigned long StopWatch< T >::TimePassed ( ) const
inline

Query the time elapsed since the most recent Start().

Returns
Elapsed time in the unit defined by the selected clock policy.

SteadyClockPolicy returns milliseconds, while HighResolutionClockPolicy returns nanoseconds.

Definition at line 199 of file mxvk_stopwatch.hpp.

199 {
200 return clock_interface.timePassed();
201 }

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