chronos/timer

Search:
Group by:
Source   Edit  

This module implements cross-platform system timer with milliseconds resolution.

Timer supports two types of clocks: system uses the most fast OS primitive to obtain wall clock time. mono uses monotonic clock time (default).

system clock is affected by discontinuous jumps in the system time. This clock is significantly faster then mono clock in most of the cases.

mono clock is not affected by discontinuous jumps in the system time. This clock is slower then system clock.

You can specify which timer you want to use -d:asyncTimer=<system/mono>.

Types

Duration = object
A Duration is the interval between to points in time. Source   Edit  
Moment = object
A Moment in time. Its value has no direct meaning, but can be compared with other Moments. Moments are captured using a monotonically non-decreasing clock (by default). Source   Edit  
SomeIntegerI64 = SomeSignedInt | uint8 | uint16 | uint32
Source   Edit  

Consts

asyncTimer {.strdefine.} = "mono"
Source   Edit  
Day = (value: 86400000000000)
Source   Edit  
Hour = (value: 3600000000000)
Source   Edit  
InfiniteDuration = (value: 9223372036854775807)
Source   Edit  
Microsecond = (value: 1000)
Source   Edit  
Millisecond = (value: 1000000)
Source   Edit  
Minute = (value: 60000000000)
Source   Edit  
Nanosecond = (value: 1)
Source   Edit  
Second = (value: 1000000000)
Source   Edit  
Week = (value: 604800000000000)
Source   Edit  
ZeroDuration = (value: 0)
Source   Edit  

Procs

func `$`(a: Duration): string {.inline, ...raises: [], tags: [], forbids: [].}
Returns string representation of Duration a. Source   Edit  
func `$`(a: Moment): string {.inline, ...raises: [], tags: [], forbids: [].}
Returns string representation of Moment a as nanoseconds value. Source   Edit  
func `*`(a: Duration; b: SomeIntegerI64): Duration {.inline, ...raises: [].}
Returns Duration multiplied by scalar integer. Source   Edit  
func `*`(a: SomeIntegerI64; b: Duration): Duration {.inline, ...raises: [].}
Returns Duration multiplied by scalar integer. Source   Edit  
func `+`(a: Duration; b: Duration): Duration {.inline, ...raises: [], tags: [],
    forbids: [].}
Duration + Duration = Duration Source   Edit  
func `+`(a: Duration; b: Moment): Moment {.inline, ...raises: [], tags: [],
    forbids: [].}
Duration + Moment = Moment Source   Edit  
func `+`(a: Moment; b: Duration): Moment {.inline, ...raises: [], tags: [],
    forbids: [].}
Moment + Duration = Moment Source   Edit  
func `+=`(a: var Duration; b: Duration) {.inline, ...raises: [], tags: [],
    forbids: [].}
Duration += Duration Source   Edit  
func `+=`(a: var Moment; b: Duration) {.inline, ...raises: [], tags: [],
                                        forbids: [].}
Moment += Duration Source   Edit  
func `-`(a, b: Moment): Duration {.inline, ...raises: [], tags: [], forbids: [].}

Moment - Moment = Duration

Note: Duration can't be negative.

Source   Edit  
func `-`(a: Duration; b: Duration): Duration {.inline, ...raises: [], tags: [],
    forbids: [].}

Duration - Duration = Duration

Note: Duration can't be negative.

Source   Edit  
func `-`(a: Moment; b: Duration): Moment {.inline, ...raises: [], tags: [],
    forbids: [].}

Moment - Duration = Moment

Note: Moment can be negative

Source   Edit  
func `-=`(a: var Duration; b: Duration) {.inline, ...raises: [], tags: [],
    forbids: [].}
Duration -= Duration Source   Edit  
func `-=`(a: var Moment; b: Duration) {.inline, ...raises: [], tags: [],
                                        forbids: [].}
Moment -= Duration Source   Edit  
func `<`(a, b: Duration): bool {.inline, ...raises: [], tags: [], forbids: [].}
Returns true if a less then b. Source   Edit  
func `<`(a, b: Moment): bool {.inline, ...raises: [], tags: [], forbids: [].}
Returns true if a less then b. Source   Edit  
func `<=`(a, b: Duration): bool {.inline, ...raises: [], tags: [], forbids: [].}
Returns true if a less or equal b. Source   Edit  
func `<=`(a, b: Moment): bool {.inline, ...raises: [], tags: [], forbids: [].}
Returns true if a less or equal b. Source   Edit  
func `==`(a, b: Duration): bool {.inline, ...raises: [], tags: [], forbids: [].}
Returns true if a equal to b. Source   Edit  
func `==`(a, b: Moment): bool {.inline, ...raises: [], tags: [], forbids: [].}
Returns true if a equal to b. Source   Edit  
func days(v: Duration): int64 {.inline, ...raises: [], tags: [], forbids: [].}
Round Duration v to days. Source   Edit  
func days(v: SomeIntegerI64): Duration {.inline, ...raises: [].}
Initialize Duration with days value v. Source   Edit  
func `div`(a: Duration; b: SomeIntegerI64): Duration {.inline, ...raises: [].}
Returns Duration which is result of dividing a Duration by scalar integer. Source   Edit  
func epochNanoSeconds(moment: Moment): int64 {....raises: [], tags: [], forbids: [].}
Source   Edit  
func epochSeconds(moment: Moment): int64 {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc fastEpochTime(): uint64 {.inline, ...deprecated: "Use Moment.now()",
                               raises: [], tags: [], forbids: [].}
Deprecated: Use Moment.now()
Procedure's resolution is millisecond. Source   Edit  
proc fromNow(t: typedesc[Moment]; a: Duration): Moment {.inline, ...raises: [].}
Returns moment in time which is equal to current moment + Duration. Source   Edit  
func hours(v: Duration): int64 {.inline, ...raises: [], tags: [], forbids: [].}
Round Duration v to hours. Source   Edit  
func hours(v: SomeIntegerI64): Duration {.inline, ...raises: [].}
Initialize Duration with hours value v. Source   Edit  
func init(t: typedesc[Moment]; value: int64; precision: Duration): Moment {.
    ...raises: [].}
Initialize Moment with absolute time value value with precision precision. Source   Edit  
func isInfinite(a: Duration): bool {.inline, ...raises: [], tags: [], forbids: [].}
Returns true if Duration a is infinite. Source   Edit  
func isZero(a: Duration): bool {.inline, ...raises: [], tags: [], forbids: [].}
Returns true if Duration a is 0. Source   Edit  
func micros(v: Duration): int64 {.inline, ...raises: [], tags: [], forbids: [].}
Source   Edit  
func micros(v: SomeIntegerI64): Duration {.inline, ...raises: [].}
Source   Edit  
func microseconds(v: Duration): int64 {.inline, ...raises: [], tags: [],
                                        forbids: [].}
Round Duration v to microseconds. Source   Edit  
func microseconds(v: SomeIntegerI64): Duration {.inline, ...raises: [].}
Initialize Duration with microseconds value v. Source   Edit  
func millis(v: Duration): int64 {.inline, ...raises: [], tags: [], forbids: [].}
Source   Edit  
func millis(v: SomeIntegerI64): Duration {.inline, ...raises: [].}
Source   Edit  
func milliseconds(v: Duration): int64 {.inline, ...raises: [], tags: [],
                                        forbids: [].}
Round Duration v to milliseconds. Source   Edit  
func milliseconds(v: SomeIntegerI64): Duration {.inline, ...raises: [].}
Initialize Duration with milliseconds value v. Source   Edit  
func minutes(v: Duration): int64 {.inline, ...raises: [], tags: [], forbids: [].}
Round Duration v to minutes. Source   Edit  
func minutes(v: SomeIntegerI64): Duration {.inline, ...raises: [].}
Initialize Duration with minutes value v. Source   Edit  
func nanos(v: Duration): int64 {.inline, ...raises: [], tags: [], forbids: [].}
Source   Edit  
func nanos(v: SomeIntegerI64): Duration {.inline, ...raises: [].}
Source   Edit  
func nanoseconds(v: Duration): int64 {.inline, ...raises: [], tags: [], forbids: [].}
Round Duration v to nanoseconds. Source   Edit  
func nanoseconds(v: SomeIntegerI64): Duration {.inline, ...raises: [].}
Initialize Duration with nanoseconds value v. Source   Edit  
proc now(t: typedesc[Moment]): Moment {.inline, ...raises: [].}
Returns current moment in time as Moment. Source   Edit  
func seconds(v: Duration): int64 {.inline, ...raises: [], tags: [], forbids: [].}
Round Duration v to seconds. Source   Edit  
func seconds(v: SomeIntegerI64): Duration {.inline, ...raises: [].}
Initialize Duration with seconds value v. Source   Edit  
func secs(v: Duration): int64 {.inline, ...raises: [], tags: [], forbids: [].}
Source   Edit  
func secs(v: SomeIntegerI64): Duration {.inline, ...raises: [].}
Source   Edit  
func toString(a: timer.Duration; parts = int.high): string {....raises: [],
    tags: [], forbids: [].}
Returns a pretty string representation of Duration a - the number of parts returned can be limited thus truncating the output to an approximation that grows more precise as the duration becomes smaller Source   Edit  
func weeks(v: Duration): int64 {.inline, ...raises: [], tags: [], forbids: [].}
Round Duration v to weeks. Source   Edit  
func weeks(v: SomeIntegerI64): Duration {.inline, ...raises: [].}
Initialize Duration with weeks value v. Source   Edit  

Templates

template high(T: typedesc[Duration]): Duration {..}
Source   Edit  
template high(T: typedesc[Moment]): Moment {..}
Source   Edit  
template low(T: typedesc[Duration]): Duration {..}
Source   Edit  
template low(T: typedesc[Moment]): Moment {..}
Source   Edit