Skip to content
FutureBlitz

    Install

    Import std.time.clock

    std.time.clock

    The monotonic clock, which never goes back or jumps as the OS's clock can, for how long things take: Instant, a reading of it; Stopwatch and Measure over it; and Sleep. The real clock's time is Timestamp's (in timestamp.fb). What reads the clock here, and in timers.fb, also takes an Instant, so code, and its tests, can give the time as a value.

    std/time/clock.fb

    Types

    Instant struct

    Public Struct Instant Implements Comparable, Hashable, Printable, Defaultable

    A reading of the monotonic clock: nanoseconds since a moment of its own, which only means something beside the program's other Instants.

    std/time/clock.fb, line 16

    • Public Static Method Now(): Instant static method #

      Now, as the clock counts it.

    • Public Static Method FromNanoseconds(count: Int64): Instant static method #

      The Instant that many nanoseconds after the clock's start, for code that gives the time.

    • Public Static Method DefaultValue(): Instant static method #

      The value to start from, like 0 for a number, "" for a String, or an empty collection.

      Doc from std.core.interfaces.Defaultable.DefaultValue.

    • Public Property Nanoseconds: Int64 property #

      How many nanoseconds after the clock's start it is.

    • Public Property Elapsed: Duration property #

      How long it's been since it, now.

    • @PanicsAtCaller Operator +(a: Instant, b: Duration): Instant operator #

      b after a. Past what an Int64 of nanoseconds holds, about 292 years, it overflows as an Int64 does.

    • @PanicsAtCaller Operator -(a: Instant, b: Duration): Instant operator #

      b before a. Past what an Int64 of nanoseconds holds, about 292 years, it overflows as an Int64 does.

    • @PanicsAtCaller Operator -(a: Instant, b: Instant): Duration operator #

      How long it is from b to a. Past what an Int64 of nanoseconds holds, about 292 years, it overflows as an Int64 does.

    • Operator <(a: Instant, b: Instant): Bool operator #

      Whether a comes before b.

      Doc from std.core.interfaces.Comparable.Operator<.

    • Public Method ToString(): String method #

      How long after the clock's start it is, like "1h2m3.5s".

    Stopwatch class

    Public Class Stopwatch

    Measures how long goes by while it runs, over as many starts and stops as it has.

    std/time/clock.fb, line 59

    • Public New() constructor #

      A Stopwatch at 0 that isn't running.

    • Public Static Method StartNew(): Stopwatch static method #

      A Stopwatch running from now, or from the Instant.

    • Public Static Method StartNew(now: Instant): Stopwatch static method #

      A Stopwatch running from now.

    • Public Property IsRunning: Bool property #

      Whether it's running.

    • Public Property Elapsed: Duration property #

      What it's measured, now or at the Instant.

    • Public Method ElapsedAt(now: Instant): Duration method #

      What it's measured at now.

    • Public Method Start() method #

      Starts it, now or at the Instant, unless it's running.

    • Public Method Start(now: Instant) method #

      Starts it at now, unless it's running.

    • Public Method Stop() method #

      Stops it, now or at the Instant, keeping what it measured, unless it's stopped.

    • Public Method Stop(now: Instant) method #

      Stops it at now, keeping what it measured, unless it's stopped.

    • Public Method Reset() method #

      Stops it at 0.

    • Public Method Restart() method #

      Starts it again from 0, now or at the Instant.

    • Public Method Restart(now: Instant) method #

      Starts it again from 0, at now.

    Functions

    Measure function

    Public Function Measure(work: Func()): Duration

    How long the work takes, on the monotonic clock.

    std/time/clock.fb, line 136

    Sleep function

    Public Function Sleep(time: Duration)

    Blocks the thread for that long, and returns at once for a Duration that isn't above 0. In Async code, Await Wait or Timer.After waits without blocking.

    std/time/clock.fb, line 144

    Report an issue with this page or with FutureBlitz on GitHub.