timer
NullTimer
Bases: Timer
A Timer class which does not actually accumulate timings.
Meant to be used in place of an optional timer.
enabled
property
Indicates whether the timer is currently enabled.
hits
property
Accumulated hit counts for each operation name.
times
property
Accumulated timings for each operation name.
clock(name)
Context manager to produce timings of operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the operation being timed. |
required |
Example
The context manager times operations that happen within its context. The following would time a time.sleep operation::
>>> import time
>>> from ndsl.performance.timer import Timer
>>> timer = Timer()
>>> with timer.clock("sleep"):
... time.sleep(1)
...
>>> timer.times
{'sleep': 1.0032463260000029}
disable()
Disable the Timer.
enable()
Enable the Timer.
reset()
Remove all accumulated timings.
start(name)
Start timing a given named operation.
stop(name)
Stop timing a given named operation, add the time elapsed to accumulated timing and increase the hit count.
Timer
Class to accumulate timings for named operations.
enabled
property
Indicates whether the timer is currently enabled.
hits
property
Accumulated hit counts for each operation name.
times
property
Accumulated timings for each operation name.
clock(name)
Context manager to produce timings of operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the operation being timed. |
required |
Example
The context manager times operations that happen within its context. The following would time a time.sleep operation::
>>> import time
>>> from ndsl.performance.timer import Timer
>>> timer = Timer()
>>> with timer.clock("sleep"):
... time.sleep(1)
...
>>> timer.times
{'sleep': 1.0032463260000029}
disable()
Disable the Timer.
enable()
Enable the Timer.
reset()
Remove all accumulated timings.
start(name)
Start timing a given named operation.
stop(name)
Stop timing a given named operation, add the time elapsed to accumulated timing and increase the hit count.