const std = @import("std"); const Io = std.Io; var configured_io: ?Io = null; pub fn init(io: Io) void { configured_io = io; } fn currentIo() Io { return configured_io orelse std.Options.debug_io; } pub fn nowNanos() i96 { return Io.Timestamp.now(currentIo(), .real).nanoseconds; } /// nanoseconds on the suspend-excluding monotonic clock; for durations only pub fn monotonicNs() u64 { return @intCast(@max(0, Io.Timestamp.now(currentIo(), .awake).nanoseconds)); } pub fn nowMs() i64 { return @intCast(@divTrunc(nowNanos(), std.time.ns_per_ms)); } pub fn nowSeconds() i64 { return @intCast(@divTrunc(nowNanos(), std.time.ns_per_s)); } test "clock runs without init and is monotone-ish across calls" { const a = nowSeconds(); const b = nowMs(); try std.testing.expect(a > 1_700_000_000); try std.testing.expect(@divTrunc(b, 1000) >= a); }