std/time

March 14, 2026 ยท View on GitHub

The std/time module provides utilities for high-precision time measurement and thread suspension.

Overview

  • Millisecond Precision: Time::now() returns current system time in milliseconds.
  • Duration Type: The Duration struct allows for intuitive time span calculations.
  • Simple Sleeping: Easy-to-use functions for suspending execution.
  • Lightweight: Minimal overhead, wrapping standard system-level time functions.

Usage

import "std/time.zc"

fn main() {
    let start = Time::now();
    
    // Sleep for 1.5 seconds
    Time::sleep(Duration::from_ms(1500));
    
    let end = Time::now();
    println "Elapsed: {end - start} ms";
}

Struct Definitions

Duration

Represents a span of time.

struct Duration {
    millis: U64;
}

Time

Static utility struct for system time operations.

struct Time {}

Methods

Duration Methods

MethodSignatureDescription
from_msDuration::from_ms(ms: U64) -> DurationCreates a Duration from a count of milliseconds.
from_secsDuration::from_secs(s: U64) -> DurationCreates a Duration from a count of seconds.

Time Static Methods

MethodSignatureDescription
nowTime::now() -> U64Returns current system time in milliseconds since the epoch.
sleepTime::sleep(d: Duration)Suspends the current thread for the specified Duration.
sleep_msTime::sleep_ms(ms: U64)Suspends the current thread for the specified count of milliseconds.