Cross-platform elapsed-time helper for the Linux, macOS, and Windows modules.


runningTime, runningTimeInternal, and get

runningTime

(-- timer) Returns a borrowed view of the module's shared timer state. It does not construct an independent timer.
  • Linux: the public member is get; the initialization timespec time0 is private. An ordinary runningTime read is immutable; @runningTimeInternal exposes a mutable view of the shared object.

runningTimeInternal

(-- timer) Exposes the shared state used by runningTime. Its storage has module lifetime. Do not move, destroy, or mutate the shared state while callers rely on it.
  • macOS: the public member is get and time0 is private, with the same shared-state design.
  • Windows: the public members are init and get.

get

(-- seconds) Reads elapsed seconds from the shared timer as an unknown Real64 value. It performs run-time clock access even when the caller has only known inputs; the result is a value, not a reference to stored seconds. Reading get does not reset the origin.
  • Linux: CLOCK_BOOTTIME is sampled during module initialization. get returns the seconds difference plus 1e-9 times the nanoseconds difference from that origin. The value is elapsed time from initialization, not the clock's raw time since boot. Normal sequential reads are nondecreasing.
  • Linux: a clock_gettime result of -1 during initialization or get prints FATAL: clock_gettime failed, result= followed by the C errno number, then terminates with status 2. This is not DEBUG-dependent. With call tracing disabled, the default output has a second newline after the diagnostic.
  • macOS: CLOCK_MONOTONIC is sampled at initialization and get subtracts that timespec with the same seconds/nanoseconds formula. The same explicit clock_gettime failure message and exit path are used.
  • Windows: initialization calls QueryPerformanceFrequency and QueryPerformanceCounter. get uses a Spinlock to serialize counter reads and accumulates counter deltas multiplied by the reciprocal frequency. Query return codes are discarded; there is no query-failure check equivalent to Linux/macOS. The elapsed-time contract assumes successful queries and no explicit reinitialization or state modification. Ordinary Spinlock checks still apply.

init

(--) Windows: queries the counter frequency, records the initial counter, and resets accumulated time to zero.
  • It is called once during module initialization.
  • A later explicit call resets the shared origin; perform it only when no concurrent timer access is possible, since init does not acquire the timer lock.

Windows fields


Examples

Linux runtime example

"String"            use
"control"           use
"linux/runningTime" use
"linux/sync/sync"   use

{} Int32 {} [
  t0: runningTime.get;
  0.01r64 sleepFor
  t1: runningTime.get;
  t1 t0 > toString print
  LF print
  0
] "main" exportFunction

Expected Output

TRUE

macOS runtime example

"String"            use
"control"           use
"macos/runningTime" use
"macos/sync/sync"   use

{} Int32 {} [
  t0: runningTime.get;
  0.01r64 sleepFor
  t1: runningTime.get;
  t1 t0 > toString print
  LF print
  0
] "main" exportFunction

Expected Output

TRUE

See also