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.
start()[source]

Start or restart this Stopwatch object.

stop()[source]

Stop the Stopwatch object and return the number of seconds since it was started.

time

Return number of seconds between starting and stopping the stopwatch (for the last time)

timelapse()[source]

Return number of seconds (float) since last call to timelapse (or to start if called for the first time).