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:

  1. import std/monotimes
  2. let a = getMonoTime()
  3. let b = getMonoTime()
  4. 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

Imports

times

Types

  1. MonoTime = object

Represents a monotonic timestamp. Source Edit

Procs

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

Source Edit

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

Increases a by b. Source Edit

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

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

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

Reduces a by b. Source Edit

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

Returns true if a happened before b. Source Edit

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

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

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

Returns true if a and b happened simultaneous. Source Edit

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

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

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

Returns the highest representable MonoTime. Source Edit

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

Returns the lowest representable MonoTime. Source Edit

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

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