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

Stopwatch policy backed by std::chrono::steady_clock. More...

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

Public Member Functions

void echo (std::string_view name) const
 Print the recorded interval in milliseconds and nanoseconds.
void start ()
 Record the beginning of a timed interval.
void stop ()
 Record the end of a timed interval.
unsigned long timePassed () const
 Return the time elapsed since the most recent start().

Detailed Description

Stopwatch policy backed by std::chrono::steady_clock.

The steady clock is monotonic, making this policy suitable for measuring elapsed wall-clock time even if the system clock is adjusted. Elapsed queries are returned in milliseconds.

Definition at line 30 of file mxvk_stopwatch.hpp.

Member Function Documentation

◆ echo()

void SteadyClockPolicy::echo ( std::string_view name) const
inline

Print the recorded interval in milliseconds and nanoseconds.

Parameters
nameDescriptive name shown with the timing result.

Call stop() before calling this function.

Definition at line 48 of file mxvk_stopwatch.hpp.

48 {
49 const auto elapsed = stop_time - start_time;
50 std::cout << "Stopwatch [" << name << "]\n"
51 << "Timer was active for : "
52 << std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count()
53 << " Milliseconds\n"
54 << "Timer was active for : "
55 << std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed).count()
56 << " Nanoseconds\n";
57 }

◆ start()

void SteadyClockPolicy::start ( )
inline

Record the beginning of a timed interval.

Definition at line 33 of file mxvk_stopwatch.hpp.

33 {
34 start_time = std::chrono::steady_clock::now();
35 }

◆ stop()

void SteadyClockPolicy::stop ( )
inline

Record the end of a timed interval.

Definition at line 38 of file mxvk_stopwatch.hpp.

38 {
39 stop_time = std::chrono::steady_clock::now();
40 }

◆ timePassed()

unsigned long SteadyClockPolicy::timePassed ( ) const
inline

Return the time elapsed since the most recent start().

Returns
Elapsed time in milliseconds.

Definition at line 63 of file mxvk_stopwatch.hpp.

63 {
64 auto now = std::chrono::steady_clock::now();
65 return std::chrono::duration_cast<std::chrono::milliseconds>(now - start_time).count();
66 }

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