Rill v0.13 Reference

Standard library · Time

time/clock

Imported as import "time/clock" as clock, its names are then clock.…. Every signature below is the one the checker infers.

Clocks: the monotonic one for measuring, the wall one for dating.

now_nanos() only ever goes forward and means nothing but differences; now_millis() is the time of day in Unix milliseconds. This is the little that turns them into something a program says: an elapsed time, a timed call, a duration in words.

(answer, took) = clock.timed(\ -> 6 * 7)
answer                                # => 42
took >= 0                             # => true
t = clock.start()
clock.since(t) >= 0                   # => true
clock.duration(1204000000)            # => 1.204 s

Functions

fn start() -> Int

A point on the monotonic clock, to measure from.

t = clock.start()
t > 0   # => true

fn since(t: Int) -> Int

Nanoseconds since a point start gave.

t = clock.start()
clock.since(t) < 1000000000   # => true

fn timed(f: () -> 'a) -> ('a, Int)

A call and how long it took, in nanoseconds.

(v, ns) = clock.timed(\ -> "done")
v   # => done

fn nanos_to_ms(ns: Int) -> Int

clock.nanos_to_ms(2500000)   # => 2

fn ms_to_nanos(ms: Int) -> Int

clock.ms_to_nanos(3)   # => 3000000

fn duration(ns: Int) -> Str

A duration in the unit that reads best: 250 ns, 12.5 us, 3.400 ms, 1.204 s, 2 m 03 s, 1 h 02 m.

clock.duration(250)          # => 250 ns
clock.duration(12500)        # => 12.5 us
clock.duration(3400000)      # => 3.400 ms
clock.duration(1204000000)   # => 1.204 s
clock.duration(123000000000) # => 2 m 03 s
clock.duration(3720000000000) # => 1 h 02 m

Tests

  • test_duration_units
  • test_timed_answers_and_measures