Skip to content

Start Timer#

timer.start()#

Starts the Timer. Should always be followed by timer.stop() later in the code.

Parameters:

Name Type Description Default
thread str | None

Option to start new thread.

None
decimals int | None

Option to define decimals for output. Minimum 0 (for no decimals) and maximum 9. If None, default is 2 decimals. May be overruled in certain cases due to humanised output.

None
Example

Basic usage:

Python
1
2
3
4
5
6
7
8
from timer import Timer

timer = Timer()
timer.start()

# Insert your code here

timer.stop()

How it appears in the terminal:

Elapsed time: 12.34 seconds

With custom thread name and decimals:

Python
1
2
3
4
5
6
7
8
from timer import Timer

timer = Timer()
timer.start(thread="custom", decimals=5)

# Insert your code here

timer.stop(thread="custom")

How it appears in the terminal:

% Elapsed time: 0.12345 seconds for thread CUSTOM