timer
Timer
Class to accumulate timings for named operations.
times
property
Accumulated timings for each operation name.
hits
property
Accumulated hit counts for each operation name.
enabled
property
Indicates whether the timer is currently enabled.
__init__(enabled=True)
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.
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}
reset()
Remove all accumulated timings.
enable()
Enable the Timer.
disable()
Disable the Timer.
NullTimer
Bases: Timer
A Timer class which does not actually accumulate timings.
Meant to be used in place of an optional timer.
__init__()
enable()
Enable the Timer.