dream_test/timing

Human-readable duration formatting for test timing.

Provides utilities for measuring and displaying test execution times in a human-friendly format that scales appropriately.

Duration Scaling

DurationDisplay Format
< 1ms0.42ms
1ms - 999ms42ms
1s - 59s1.2s
1m - 59m2m 30s
>= 1h1h 15m

Example

import dream_test/timing

timing.format_duration_ms(42)      // "42ms"
timing.format_duration_ms(1500)    // "1.5s"
timing.format_duration_ms(90_000)  // "1m 30s"

Values

pub fn format_duration_ms(duration_ms: Int) -> String

Format a duration in milliseconds as a human-readable string.

Automatically scales to the most appropriate unit:

  • Milliseconds for durations under 1 second
  • Seconds (with decimal) for durations under 1 minute
  • Minutes and seconds for durations under 1 hour
  • Hours and minutes for longer durations

Examples

format_duration_ms(0)        // "0ms"
format_duration_ms(42)       // "42ms"
format_duration_ms(1500)     // "1.5s"
format_duration_ms(65_000)   // "1m 5s"
format_duration_ms(3_665_000) // "1h 1m"
pub fn format_duration_us(duration_us: Int) -> String

Format a duration in microseconds as a human-readable string.

Similar to format_duration_ms but accepts microseconds. Useful when working with high-precision timing.

Examples

format_duration_us(500)       // "0.5ms"
format_duration_us(42_000)    // "42ms"
format_duration_us(1_500_000) // "1.5s"
pub fn now_ms() -> Int

Get the current monotonic time in milliseconds.

Use this to measure elapsed time between two points. Monotonic time is not affected by system clock changes.

Example

let start = now_ms()
// ... do work ...
let elapsed = now_ms() - start
io.println("Took " <> format_duration_ms(elapsed))
pub fn now_us() -> Int

Get the current monotonic time in microseconds.

Higher precision version of now_ms() for sub-millisecond timing.

Search Document