monotimes
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 to always increase, meaning that that the following is guaranteed to work:
let a = getMonoTime() # ... do some work 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
Imports
Types
Procs
proc getMonoTime(): MonoTime {...}{.tags: [TimeEffect], raises: [].}-
Get the current
MonoTimetimestamp.When compiled with the JS backend and executed in a browser, this proc calls
Source Editwindow.performance.now(), which is not supported by older browsers. See MDN for more information. proc ticks(t: MonoTime): int64 {...}{.raises: [], tags: [].}- Returns the raw ticks value from a
MonoTime. This value always uses nanosecond time resolution. Source Edit proc `$`(t: MonoTime): string {...}{.raises: [], tags: [].}- Source Edit
proc `-`(a, b: MonoTime): Duration {...}{.raises: [], tags: [].}- Returns the difference between two
MonoTimetimestamps as aDuration. Source Edit proc `+`(a: MonoTime; b: Duration): MonoTime {...}{.raises: [], tags: [].}- Increases
abyb. Source Edit proc `-`(a: MonoTime; b: Duration): MonoTime {...}{.raises: [], tags: [].}- Reduces
abyb. Source Edit proc `<`(a, b: MonoTime): bool {...}{.raises: [], tags: [].}- Returns true if
ahappened beforeb. Source Edit proc `<=`(a, b: MonoTime): bool {...}{.raises: [], tags: [].}- Returns true if
ahappened beforebor if they happened simultaneous. Source Edit proc `==`(a, b: MonoTime): bool {...}{.raises: [], tags: [].}- Returns true if
aandbhappened simultaneous. 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
© 2006–2021 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/monotimes.html