No matching definitions.

tur/time

stdlib/time.tur

Time capability implementation using platform time functions.

Since: Phase 16

defn

Real-Time

(Real-Time)

create a wall-clock Time capability backed by libc time().

A heap-allocated Time struct with: now -- returns milliseconds since the Unix epoch (second precision). sleep -- sleeps for the requested number of milliseconds via nanosleep, retrying on EINTR. Free with Real-Time-free when done.

(let [t (Real-Time)] ...)

Since: Phase 16

defn

Real-Time-free

(Real-Time-free [t])

release a Time capability created by Real-Time.

tthe Time pointer returned by Real-Time.

Since: Phase 16

defn

HighRes-Time

(HighRes-Time)

create a CPU-clock Time capability backed by clock().

A heap-allocated Time struct with: now -- returns CPU time in milliseconds (based on CLOCKS_PER_SEC). sleep -- sleeps for the requested number of milliseconds via nanosleep. Note: now measures CPU time, not wall-clock time. Free with HighRes-Time-free when done.

(let [t (HighRes-Time)] ...)

Since: Phase 16

defn

HighRes-Time-free

(HighRes-Time-free [t])

release a Time capability created by HighRes-Time.

tthe Time pointer returned by HighRes-Time.

Since: Phase 16

defn

Mock-Time

(Mock-Time)

create a controllable Time capability for testing.

A heap-allocated Time struct backed by an internal integer counter (initially 0 ms). now returns the current counter value; sleep advances the counter by the requested amount without blocking. Use mock-time-set and mock-time-get to inspect and manipulate time. Free with Mock-Time-free when done.

(let [t (Mock-Time)] (mock-time-set t 5000) ...)

Since: Phase 16

defn

Mock-Time-free

(Mock-Time-free [t])

release a Time capability created by Mock-Time.

tthe Time pointer returned by Mock-Time.

Since: Phase 16

defn

mock-time-set

(mock-time-set [t new_time])

set the current time on a Mock-Time instance.

tthe Mock-Time pointer.
new_timethe new time value in milliseconds.
(mock-time-set t 10000)  ; set mock clock to 10 seconds

Since: Phase 16

defn

mock-time-get

(mock-time-get [t])

read the current time from a Mock-Time instance.

tthe Mock-Time pointer.

The current mock time in milliseconds as an int.

(mock-time-get t)  ; => 10000

Since: Phase 16

defn

get-time-ms

(get-time-ms)

return the current wall-clock time in milliseconds since epoch.

Seconds since the Unix epoch multiplied by 1000 (second precision).

(get-time-ms)  ; => 1747123456000

Since: Phase 16

defn

sleep-ms

(sleep-ms [ms])

suspend execution for a given number of milliseconds.

msnumber of milliseconds to sleep (no-op if <= 0).
(sleep-ms 250)  ; sleep for a quarter second

Since: Phase 16

defn

get-cpu-time

(get-cpu-time)

return the current process CPU time in milliseconds.

clock() * 1000 / CLOCKS_PER_SEC -- CPU milliseconds consumed by the current process.

(get-cpu-time)  ; => 42  (42 ms of CPU time used so far)

Since: Phase 16