Skip to content

std/time

Sleeping and reading clocks. Import with import "std/time";.

sleep and now work everywhere. mono_ns is native only.

void sleep(ms: int)

Suspends the program for ms milliseconds. In the playground this keeps the browser responsive, which is what makes render loops possible. See Playground Functions.

time.sleep(16); # roughly one 60 fps frame
int now()

Returns the current wall-clock time as seconds since the Unix epoch.

let today = time.now() / 86400; # days since 1970-01-01
int mono_ns()

Returns a monotonic clock reading in nanoseconds. Native only. The absolute value is meaningless on its own. Subtract two readings to measure elapsed time. Unlike now, it never jumps backwards.

let start = time.mono_ns();
work();
let elapsed_ms = (time.mono_ns() - start) / 1000000;