Skip to content

std.time

Monotonic-clock helpers.

std.time exposes a single pair of helpers around a monotonic clock, appropriate for measuring elapsed durations within a process.

export def monotonic_nanos() -> u64
export def elapsed_nanos(start: u64) -> u64
  • monotonic_nanos() reads the platform monotonic clock and returns nanoseconds. The epoch is unspecified; only differences are meaningful.
  • elapsed_nanos(start) returns monotonic_nanos() - start, clamped to 0 if the clock appears to have moved backwards (the clamp is defensive; on a monotonic clock it shouldn’t happen).
import std.time as time
import std.io as io
def main() -> None:
let start: u64 = time.monotonic_nanos()
do_work()
let elapsed: u64 = time.elapsed_nanos(start)
# ... format and print elapsed ...
return None

For wall-clock time, calendar arithmetic, or formatted timestamps, additional helpers will be added as use cases arrive.