std.time
std.time
The std.time module provides access to the current runtime clock and basic sleep control.
Import
import std.time as timeAPI
| Function | Signature | Description |
|---|---|---|
now_ms | func now_ms() -> i64 | Current time in milliseconds since epoch |
sleep_ms | func sleep_ms(ms: i64) | Pause the current thread for at least ms milliseconds |
Example
import std.time as time
func main() -> i32: let t = time.now_ms() return 0now_ms returns i64. There is no string.from_i64 in the current standard library, so printing a timestamp directly is not supported without an intermediate cast. To compare timestamps, use arithmetic:
Timing elapsed duration
import std.time as time
func main() -> i32: let start = time.now_ms() let i: i32 = 0 while (i < 1000000): i = i + 1 let elapsed = time.now_ms() - start if (elapsed > 0): return 0 return 1Sleeping
import std.time as time
func main() -> i32: let start = time.now_ms() time.sleep_ms(25) let elapsed = time.now_ms() - start if (elapsed >= 10): return 0 return 1Full reference
| Function | Signature | Description |
|---|---|---|
now_ms | func now_ms() -> i64 | milliseconds since epoch |
sleep_ms | func sleep_ms(ms: i64) | sleep for at least ms milliseconds |