std/time
Sleeping and reading clocks. Import with import "std/time";.
sleep and now work everywhere. mono_ns is native only.
Functions
Section titled “Functions”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 frameint now()Returns the current wall-clock time as seconds since the Unix epoch.
let today = time.now() / 86400; # days since 1970-01-01mono_ns
Section titled “mono_ns”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;