A monotonic, high performance timer.

Timer.start() is used to initialize the timer and gives the caller an opportunity to check for the existence of a supported clock. Once a supported clock is discovered, it is assumed that it will be available for the duration of the Timer’s use.

Monotonicity is ensured by saturating on the most previous sample. This means that while timings reported are monotonic, they’re not guaranteed to tick at a steady rate as this is up to the underlying system.

Fields

started: Instant,
previous: Instant,

Functions

fn lap(self: *Timer) u64

Returns the current value of the timer in nanoseconds, then resets it.

fn read(self: *Timer) u64

Reads the timer value since start or the last reset in nanoseconds.

fn reset(self: *Timer) void

Resets the timer value to 0/now.

fn start() Error!Timer

Initialize the timer by querying for a supported clock. Returns `error.TimerUns…

Initialize the timer by querying for a supported clock. Returns error.TimerUnsupported when such a clock is unavailable. This should only fail in hostile environments such as linux seccomp misuse.

Error Sets