API¶
Module et_stopwatch¶
A context manager class for timing a piece of code.
-
class
et_stopwatch.
Stopwatch
(message='', ndigits=6)[source]¶ Context manager class for timing a code fragment.
Usage:
with Stopwatch('This took me') as sw: for i in range(3): sleep(1) print(i,sw.timelapse(),'s) 0 1.004215 s 1 1.003996 s 2 1.001949 s This took me 3.010238 s
Parameters: - comment (str) – text in front of the total time. If None nothing is printed. Default is empty str,
- ndigits (int) – number of digits after the decimal sign.
-
time
¶ Return number of seconds between starting and stopping the stopwatch (for the last time)