Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
helios::utils::Timer< Clock > Class Template Reference

High–resolution timer with configurable clock and rich elapsed API. More...

#include <timer.hpp>

Public Types

using ClockType = Clock
using TimePoint = typename Clock::time_point
using Duration = typename Clock::duration

Public Member Functions

constexpr Timer () noexcept(noexcept(Clock::now()))=default
 Constructs timer and immediately resets start timestamp.
constexpr Timer (const Timer &) noexcept(std::is_nothrow_copy_constructible_v< Clock >)=default
constexpr Timer (Timer &&) noexcept(std::is_nothrow_move_constructible_v< Clock >)=default
constexpr ~Timer () noexcept(std::is_nothrow_destructible_v< Clock >)=default
constexpr Timeroperator= (const Timer &) noexcept(std::is_nothrow_copy_assignable_v< Clock >)=default
constexpr Timeroperator= (Timer &&) noexcept(std::is_nothrow_move_assignable_v< Clock >)=default
constexpr void Reset () noexcept(noexcept(Clock::now()))
 Reset the timer start point to current time.
template<details::DurationTrait Units = Duration>
constexpr Units ElapsedDuration () const
 Get elapsed time as a std::chrono::duration.
template<utils::ArithmeticTrait Type = typename Duration::rep, details::DurationTrait Units = Duration>
constexpr Type Elapsed () const
 Get elapsed time converted to an arithmetic value with specified units.
constexpr double ElapsedSec () const
 Elapsed time in seconds as double.
constexpr double ElapsedMilliSec () const
 Elapsed time in milliseconds as double.
constexpr int64_t ElapsedMicroSec () const
 Elapsed time in microseconds as 64-bit integer.
constexpr int64_t ElapsedNanoSec () const
 Elapsed time in nanoseconds as 64-bit integer.
constexpr TimePoint Start () const noexcept
 Get the raw start timestamp of the timer.

Detailed Description

template<details::ClockTrait Clock = std::chrono::steady_clock>
class helios::utils::Timer< Clock >

High–resolution timer with configurable clock and rich elapsed API.

The timer measures elapsed time from the last reset point.

  • The clock type is configurable via the template parameter Clock.
  • Users can query elapsed time as:
    • A raw Clock::duration.
    • Any std::chrono::duration (via ElapsedDuration).
    • Arbitrary arithmetic type with specified time unit (via Elapsed).
    • Convenience helpers (seconds, milliseconds, microseconds, nanoseconds).
Note
The default clock is std::chrono::steady_clock.
Template Parameters
ClockClock type used to measure time. Must satisfy details::ClockTrait.

Definition at line 67 of file timer.hpp.

Member Typedef Documentation

◆ ClockType

template<details::ClockTrait Clock = std::chrono::steady_clock>
using helios::utils::Timer< Clock >::ClockType = Clock

Definition at line 69 of file timer.hpp.

◆ Duration

template<details::ClockTrait Clock = std::chrono::steady_clock>
using helios::utils::Timer< Clock >::Duration = typename Clock::duration

Definition at line 71 of file timer.hpp.

◆ TimePoint

template<details::ClockTrait Clock = std::chrono::steady_clock>
using helios::utils::Timer< Clock >::TimePoint = typename Clock::time_point

Definition at line 70 of file timer.hpp.

Constructor & Destructor Documentation

◆ Timer() [1/3]

template<details::ClockTrait Clock = std::chrono::steady_clock>
helios::utils::Timer< Clock >::Timer ( )
constexprdefaultnoexcept

Constructs timer and immediately resets start timestamp.

◆ Timer() [2/3]

template<details::ClockTrait Clock = std::chrono::steady_clock>
helios::utils::Timer< Clock >::Timer ( const Timer< Clock > & ) const
constexprdefaultnoexcept

◆ Timer() [3/3]

template<details::ClockTrait Clock = std::chrono::steady_clock>
helios::utils::Timer< Clock >::Timer ( Timer< Clock > && ) const
constexprdefaultnoexcept

◆ ~Timer()

template<details::ClockTrait Clock = std::chrono::steady_clock>
helios::utils::Timer< Clock >::~Timer ( )
constexprdefaultnoexcept

Member Function Documentation

◆ Elapsed()

template<details::ClockTrait Clock>
template<utils::ArithmeticTrait Type, details::DurationTrait Units>
Type helios::utils::Timer< Clock >::Elapsed ( ) const
nodiscardconstexpr

Get elapsed time converted to an arithmetic value with specified units.

This method allows querying elapsed time in arbitrary precision and units, for example:

  • Elapsed<double, std::chrono::seconds>()
  • Elapsed<std::uint64_t, std::chrono::microseconds>()
    Template Parameters
    TypeArithmetic type used for the returned value.
    UnitsDuration type representing the desired time unit.
    Returns
    Elapsed time as Type, where the underlying duration is Units.

Definition at line 175 of file timer.hpp.

◆ ElapsedDuration()

template<details::ClockTrait Clock>
template<details::DurationTrait Units>
Units helios::utils::Timer< Clock >::ElapsedDuration ( ) const
nodiscardconstexpr

Get elapsed time as a std::chrono::duration.

This is the primary API for time measurement and should be preferred when working with std::chrono.

Template Parameters
UnitsDuration type to convert to. Must satisfy details::DurationTrait. Defaults to Clock::duration.
Returns
Elapsed time since last reset as Units.

Definition at line 167 of file timer.hpp.

◆ ElapsedMicroSec()

template<details::ClockTrait Clock = std::chrono::steady_clock>
int64_t helios::utils::Timer< Clock >::ElapsedMicroSec ( ) const
inlinenodiscardconstexpr

Elapsed time in microseconds as 64-bit integer.

Returns
Elapsed time since last reset in microseconds.

Definition at line 141 of file timer.hpp.

◆ ElapsedMilliSec()

template<details::ClockTrait Clock = std::chrono::steady_clock>
double helios::utils::Timer< Clock >::ElapsedMilliSec ( ) const
inlinenodiscardconstexpr

Elapsed time in milliseconds as double.

Returns
Elapsed time since last reset in milliseconds.

Definition at line 133 of file timer.hpp.

◆ ElapsedNanoSec()

template<details::ClockTrait Clock = std::chrono::steady_clock>
int64_t helios::utils::Timer< Clock >::ElapsedNanoSec ( ) const
inlinenodiscardconstexpr

Elapsed time in nanoseconds as 64-bit integer.

Returns
Elapsed time since last reset in nanoseconds.

Definition at line 149 of file timer.hpp.

◆ ElapsedSec()

template<details::ClockTrait Clock = std::chrono::steady_clock>
double helios::utils::Timer< Clock >::ElapsedSec ( ) const
inlinenodiscardconstexpr

Elapsed time in seconds as double.

Returns
Elapsed time since last reset in seconds.

Definition at line 125 of file timer.hpp.

◆ operator=() [1/2]

template<details::ClockTrait Clock = std::chrono::steady_clock>
Timer & helios::utils::Timer< Clock >::operator= ( const Timer< Clock > & )
constexprdefaultnoexcept

◆ operator=() [2/2]

template<details::ClockTrait Clock = std::chrono::steady_clock>
Timer & helios::utils::Timer< Clock >::operator= ( Timer< Clock > && )
constexprdefaultnoexcept

◆ Reset()

template<details::ClockTrait Clock = std::chrono::steady_clock>
void helios::utils::Timer< Clock >::Reset ( )
inlineconstexprnoexcept

Reset the timer start point to current time.

Definition at line 91 of file timer.hpp.

◆ Start()

template<details::ClockTrait Clock = std::chrono::steady_clock>
TimePoint helios::utils::Timer< Clock >::Start ( ) const
inlinenodiscardconstexprnoexcept

Get the raw start timestamp of the timer.

Returns
Starting time point.

Definition at line 157 of file timer.hpp.