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

Stopwatch policy backed by std::chrono::high_resolution_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::high_resolution_clock.

This policy provides the clock's finest available resolution. Elapsed queries are returned in nanoseconds.

Definition at line 78 of file mxvk_stopwatch.hpp.

Member Function Documentation

◆ echo()

void HighResolutionClockPolicy::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 96 of file mxvk_stopwatch.hpp.

96 {
97 const auto elapsed = stop_time - start_time;
98 std::cout << "Stopwatch [" << name << "]\n"
99 << "Timer was active for : "
100 << std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count()
101 << " Milliseconds\n"
102 << "Timer was active for : "
103 << std::chrono::duration_cast<std::chrono::nanoseconds>(elapsed).count()
104 << " Nanoseconds\n";
105 }

◆ start()

void HighResolutionClockPolicy::start ( )
inline

Record the beginning of a timed interval.

Definition at line 81 of file mxvk_stopwatch.hpp.

81 {
82 start_time = std::chrono::high_resolution_clock::now();
83 }

◆ stop()

void HighResolutionClockPolicy::stop ( )
inline

Record the end of a timed interval.

Definition at line 86 of file mxvk_stopwatch.hpp.

86 {
87 stop_time = std::chrono::high_resolution_clock::now();
88 }

◆ timePassed()

unsigned long HighResolutionClockPolicy::timePassed ( ) const
inline

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

Returns
Elapsed time in nanoseconds.

Definition at line 111 of file mxvk_stopwatch.hpp.

111 {
112 auto now = std::chrono::high_resolution_clock::now();
113 return std::chrono::duration_cast<std::chrono::nanoseconds>(now - start_time).count();
114 }

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