Class Timer

Class Documentation

class Timer

Encapsulates basic usage of chrono, providing a means to calculate float durations between time points via function calls.

Public Types

using Seconds = std::ratio<1>
using Milliseconds = std::ratio<1, 1000>
using Microseconds = std::ratio<1, 1000000>
using Nanoseconds = std::ratio<1, 1000000000>
using Clock = std::chrono::steady_clock
using DefaultResolution = Seconds

Public Functions

Timer()
void start()

Starts the timer, elapsed() now returns the duration since start()

void lap()

Laps the timer, elapsed() now returns the duration since the last lap()

template<typename T = DefaultResolution>
inline float stop()

Stops the timer, elapsed() now returns 0.

Returns:

The total execution time between start() and stop()

template<typename T = DefaultResolution>
inline float elapsed()

Calculates the time difference between now and when the timer was started if lap() was called, then between now and when the timer was last lapped.

Returns:

The duration between the two time points (default in seconds)

template<typename T = DefaultResolution>
inline float tick()

Calculates the time difference between now and the last time this function was called.

Returns:

The duration between the two time points (default in seconds)

bool is_running() const

Check if the timer is running.