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.
関連
プロシージャ
proc getMonoTime(): MonoTime {...}{.tags: [TimeEffect], raises: [].}
-
Get the current MonoTime timestamp.
When compiled with the JS backend and executed in a browser, this proc calls window.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. ソース 編集
proc `$`(t: MonoTime): string {...}{.raises: [], tags: [].}
- ソース 編集
proc `-`(a, b: MonoTime): Duration {...}{.raises: [], tags: [].}
- Returns the difference between two MonoTime timestamps as a Duration. ソース 編集
proc `+`(a: MonoTime; b: Duration): MonoTime {...}{.raises: [], tags: [].}
- Increases a by b. ソース 編集
proc `-`(a: MonoTime; b: Duration): MonoTime {...}{.raises: [], tags: [].}
- Reduces a by b. ソース 編集
proc `<`(a, b: MonoTime): bool {...}{.raises: [], tags: [].}
- Returns true if a happened before b. ソース 編集
proc `<=`(a, b: MonoTime): bool {...}{.raises: [], tags: [].}
- Returns true if a happened before b or if they happened simultaneous. ソース 編集
proc `==`(a, b: MonoTime): bool {...}{.raises: [], tags: [].}
- Returns true if a and b happened simultaneous. ソース 編集
proc high(typ: typedesc[MonoTime]): MonoTime
- Returns the highest representable MonoTime. ソース 編集
proc low(typ: typedesc[MonoTime]): MonoTime
- Returns the lowest representable MonoTime. ソース 編集