# std/monotimes

Dark Mode

- Manual
- Standard library
- Index
- Compiler docs
- Fusion docs
- devel, stable

Search:
Source Edit

The `std/monotimes` module implements monotonic timestamps. A monotonic timestamp represents the time that has passed since some system defined point in time. The monotonic timestamps are guaranteed not to decrease, meaning that that the following is guaranteed to work:

Example:

    import std/monotimes
    let a = getMonoTime()
    let b = getMonoTime()
    assert a <= b

This is not guaranteed for the `times.Time` type! This means that the `MonoTime` should be used when measuring durations of time with high precision.

However, since `MonoTime` represents the time that has passed since some unknown time origin, it cannot be converted to a human readable timestamp. If this is required, the `times.Time` type should be used instead.

The `MonoTime` type stores the timestamp in nanosecond resolution, but note that the actual supported time resolution differs for different systems.

# See also

- times module

# Imports

times

# Types

    MonoTime = object
      ticks: int64

  Represents a monotonic timestamp. Source Edit

# Procs

    proc `$`(t: MonoTime): string {....raises: [], tags: [].}

  Source Edit

    proc `+`(a: MonoTime; b: Duration): MonoTime {....raises: [], tags: [].}

  Increases `a` by `b`. Source Edit

    proc `-`(a, b: MonoTime): Duration {....raises: [], tags: [].}

  Returns the difference between two `MonoTime` timestamps as a `Duration`. Source Edit

    proc `-`(a: MonoTime; b: Duration): MonoTime {....raises: [], tags: [].}

  Reduces `a` by `b`. Source Edit

    proc `<=`(a, b: MonoTime): bool {....raises: [], tags: [].}

  Returns true if `a` happened before `b` or if they happened simultaneous. Source Edit

    proc `<`(a, b: MonoTime): bool {....raises: [], tags: [].}

  Returns true if `a` happened before `b`. Source Edit

    proc `==`(a, b: MonoTime): bool {....raises: [], tags: [].}

  Returns true if `a` and `b` happened simultaneous. Source Edit

    proc getMonoTime(): MonoTime {....tags: [TimeEffect], raises: [].}

  Returns the current `MonoTime` timestamp.

  When compiled with the JS backend and executed in a browser, this proc calls `window.performance.now()`. See MDN for more information.

  Source Edit

    proc high(typ: typedesc[MonoTime]): MonoTime

  Returns the highest representable `MonoTime`. Source Edit

    proc low(typ: typedesc[MonoTime]): MonoTime

  Returns the lowest representable `MonoTime`. Source Edit

    proc ticks(t: MonoTime): int64 {....raises: [], tags: [].}

  Returns the raw ticks value from a `MonoTime`. This value always uses nanosecond time resolution. Source Edit