Timer
- class typhon.utils.Timer(info=None, verbose=True)[source]
Provide a simple time profiling utility
- Parameters:
- Returns:
The duration between start and end time.
- Return type:
Examples
Timer in with statement:
>>> import time >>> with Timer(): ... time.sleep(1) elapsed time: 0:00:01.003186
Timer as object (allows to store
datetime.timedelta
):>>> import time >>> t = Timer().start() >>> time.sleep(1) >>> dt = t.stop() elapsed time: 0:00:01.004756
As function decorator:
>>> @Timer() ... def own_function(s): ... import time ... time.sleep(s) >>> own_function(1) own_function: 0:00:01.004667
Use it in format strings:
>>> from typhon.utils import Timer >>> timer = Timer().start() >>> print(f"{timer} elapsed") 0:00:00.000111 hours elapsed
- __init__(info=None, verbose=True)[source]
Create a timer object.
Methods
__init__
([info, verbose])Create a timer object.
start
()Start timer.
stop
()Stop timer and print info message
Attributes
elapsed
Get the elapsed time as timedelta object