xur_

> module

std::time

timing, durations and sleep

use std::time; feature time in the browser (in-memory)

std::time provides monotonic timing with Instant and Duration, plus a sleep function.

> functions

# from_millis(ms: i64) -> Duration

A duration of ms milliseconds. A negative ms is a runtime error.

# from_secs(secs: i64 | f64) -> Duration

A duration of secs seconds, which may be fractional. A negative or non-finite number is a runtime error.

# now() -> Instant

The current time on a monotonic clock, for measuring how long things take.

# sleep(duration: i64 | Duration)

Pauses the current thread for duration milliseconds, or for a Duration. A negative number is a runtime error.

> types

┌ type Duration
# duration.as_secs_f64() -> f64

The duration in seconds, with a fraction.

# duration.micros() -> i64

The whole duration in milliseconds, microseconds or nanoseconds.

# duration.millis() -> i64

The whole duration in milliseconds, microseconds or nanoseconds.

# duration.nanos() -> i64

The whole duration in milliseconds, microseconds or nanoseconds.

# duration.secs() -> i64

The whole seconds.

┌ type Instant
# instant.elapsed() -> Duration

The time since the Instant was taken.

> functions

A Duration prints in the largest unit that is at least 1, such as 1.234s, 42ms, 100µs or 500ns.

> examples

use std::io;
use std::time;

fn main() {
    let start = time::now();
    time::sleep(time::from_millis(20));
    let elapsed = start.elapsed();
    io::println("took {}", elapsed);
    io::println("{} ms", elapsed.millis());
}