Timers
Clock = Nullary[int]
module-attribute
The type representing clocks which return time in nanoseconds.
Elapsed
Represents elapsed time, in nanoseconds and human-readable format.
Source code in aoc/timers.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
nanoseconds: int = field()
class-attribute
instance-attribute
The time elapsed, in nanoseconds.
rounding: int = field(default=DEFAULT_ROUNDING)
class-attribute
instance-attribute
The rounding to use when converting to human-readable format.
string: str = field(init=False)
class-attribute
instance-attribute
The time elapsed, in human-readable format.
Timer
Represents timers.
Source code in aoc/timers.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
clock: Clock = field(default=default_clock)
class-attribute
instance-attribute
The clock to use.
created: int = field(init=False)
class-attribute
instance-attribute
The creation time of the timer.
elapsed(rounding: int = DEFAULT_ROUNDING) -> Elapsed
Returns the time elapsed since the creation of this timer.
Returns:
Type | Description |
---|---|
Elapsed
|
The time elapsed since the creation of this timer. |
Source code in aoc/timers.py
62 63 64 65 66 67 68 |
|
reset() -> Self
Creates and returns a new timer of the same type with the same clock.
Returns:
Type | Description |
---|---|
Self
|
The timer created. |
Source code in aoc/timers.py
70 71 72 73 74 75 76 |
|
now(clock: Clock = default_clock) -> Timer
Creates a new timer with the given (or default) clock.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clock |
Clock
|
The clock to use. |
perf_counter_ns
|
Returns:
Type | Description |
---|---|
Timer
|
The timer created. |
Source code in aoc/timers.py
79 80 81 82 83 84 85 86 87 88 |
|