tim
Time operations - get current time in seconds (tim_now) and milliseconds (tim_ms), sleep for seconds, compute elapsed milliseconds since a t0, compute a future timestamp now + delta_ms, produce a monotonic stamp object, and format a millisecond duration as a human-readable string.
Load with: use tim
What this module does
tim wraps three host-injected syscalls (tim_now,
tim_slp, tim_ms) in a stable, readable API. All
millisecond-based timing (for deadlines, TTLs, rate limiting) builds on
tim.ms(). For more advanced deadline and retry helpers, see
the lim module which builds on tim.
Quick example
use tim
# Get time
prn(timno()) # seconds since epoch (float)
prn(timms()) # ms since epoch
# Sleep
timsl(2) # sleep 2 seconds
# Elapsed
t0 = timms()
# ... do work ...
prn(timel(t0)) # ms elapsed
# Future timestamp
deadline = timaf(5000) # now + 5 seconds
# Stamp
st = timst()
prn(st.wall) # ms timestamp
prn(st.tag) # now() value
# Format duration
prn(timfm(750)) # "750ms"
prn(timfm(3200)) # "3.2s"
# Namespace style
prn(tim.ms())
Functions
Current time
timno() / tim.now()Returns current time in seconds (from tim_now host syscall).
timms() / tim.ms() / tim.nowms()Returns current time in milliseconds (from tim_ms host syscall).
Sleep and timing
timsl(sec) / tim.slp(sec)Sleeps for sec seconds.
timel(t0_ms) / tim.elapsed(t0)Returns the number of milliseconds elapsed since t0_ms.
timaf(delta_ms) / tim.after(delta)Returns a future timestamp: now + delta_ms. Use as a deadline.
Stamps and formatting
timst() / tim.stamp()Returns a monotonic-ish stamp object {wall: ms, tag: now} for ordering events.
timfm(ms) / tim.fmt(ms)Formats a millisecond duration as a human-readable string: "750ms" for values under 1 second, "3.2s" for larger values. Handles negative durations with a leading "-".
Notes
- No stdlib dependencies - wraps
tim_now,tim_slp, andtim_mshost syscalls.