Class timer_t
Defined in File timer.hpp
Class Documentation
-
class timer_t
Utility timer for elapsed-time measurement and pacing.
The timer measures elapsed time between
tic()andtoc()and provides sleep/pacing helpers for loop-rate control.Public Types
Smart pointers — shared.
Public Functions
-
inline timer_t()
Default constructor. This function starts the timer.
-
~timer_t() = default
Default destructor.
-
inline void tic()
Set/Reset the timer for measuring elapsed time.
-
inline duration_t toc()
Stops the timer and returns the elapsed time.
- Returns:
Elapsed duration since the last
tic().
-
inline bool over(duration_t minDuration_)
Checks if the timer is running for more than the specified duration
- Parameters:
minDuration_ – Duration threshold used for the comparison.
- Returns:
truewhen elapsed time is greater thanminDuration_.
-
inline duration_t pace(duration_t minDuration_)
Either do nothing or sleep to pace the execution to a minimum FPS.
- Parameters:
minDuration_ – Minimum cycle duration to enforce.
- Returns:
Elapsed duration since the last
tic()after pacing.
-
inline void sleep(duration_t duration_)
Waits for a specified duration.
- Parameters:
duration_ – Sleep duration requested for the current thread.
Public Static Functions
-
static inline timer_t::unique_ptr make_unique()
Make unique pointer function
- Returns:
Unique pointer owning a new timer instance.
Make shared pointer function
- Returns:
Shared pointer owning a new timer instance.
Private Functions
-
inline duration_t __elapsed_time(duration_t offset_)
Computes the elapsed time since the last tic() call (0 if negative)
- Parameters:
offset_ – Target duration used to compute remaining wait time.
- Returns:
Remaining duration until
offset_, clamped to zero.
-
inline duration_t __toc()
Computes the elapsed time since the last tic() call
- Returns:
Elapsed duration in microseconds since
tic().
-
inline void __sleep(duration_t duration_)
Sleeps a thread for a specified duration
- Parameters:
duration_ – Duration used in
std::this_thread::sleep_for.
Private Members
-
time_point<high_resolution_clock> startTime
Start time.