stopwatch package

Submodules

stopwatch.stopwatch module

Stopwatch class for timing portions of python code

class stopwatch.stopwatch.Tick(id: int, name: str, time: float, duration: float, action: str)[source]

Bases: object

id: int
name: str
time: float
duration: float
action: str
class stopwatch.stopwatch.Stopwatch(precision=None)[source]

Bases: object

Stopwatch Instance

A typical lifecycle of the stopwatch:

[creation] –> [start] –> [tick, pause, resume] –> [stop]

start()[source]

Start the stopwatch

tick(name=None)[source]

Record a tick

Return type:

Time since the last tick

pause()[source]

Pause the stopwatch (Ticks are not recorded until resumed)

resume()[source]

Resume

Return type:

Time for which the instance was paused

stop()[source]

Stops the stopwatch

Return type:

Total time (including pause-time)

get_time_paused(start_idx=0, end_idx=-1)[source]

Get pause-time between different ticks

property time_paused

Get pause-time between different ticks

property time_active
property time_total
get_time_elapsed(start_key: int = 0, end_key: int = -1, exclude_pause: bool = True)[source]

Get time elapsed between different ticks

If there are multiple matches for start or end ticks, the following two ticks are selected: - the chronologically first matching tick for start - the chronologically last matching tick for end

Parameters:

start_key (int or str)

exclude_pause: bool

If True, pause-time is not counted. The default is True.

Return type:

Total runtime (with or without pause-time)

property time_elapsed

Get time elapsed between different ticks

If there are multiple matches for start or end ticks, the following two ticks are selected: - the chronologically first matching tick for start - the chronologically last matching tick for end

Parameters:

start_key (int or str)

exclude_pause: bool

If True, pause-time is not counted. The default is True.

Return type:

Total runtime (with or without pause-time)

get_ticks(key=None)[source]
last()[source]

Return the time duration of the last tick i.e. time between the last two ticks

current()[source]

Return the time elapsed since the last tick

stopwatch.stopwatch.main()[source]

Module contents

Stopwatch class for timing your python code with support for pause, resume and multiple named-ticks.

class stopwatch.Stopwatch(precision=None)[source]

Bases: object

Stopwatch Instance

A typical lifecycle of the stopwatch:

[creation] –> [start] –> [tick, pause, resume] –> [stop]

current()[source]

Return the time elapsed since the last tick

get_ticks(key=None)[source]
get_time_elapsed(start_key: int = 0, end_key: int = -1, exclude_pause: bool = True)[source]

Get time elapsed between different ticks

If there are multiple matches for start or end ticks, the following two ticks are selected: - the chronologically first matching tick for start - the chronologically last matching tick for end

Parameters:

start_key (int or str)

exclude_pause: bool

If True, pause-time is not counted. The default is True.

Return type:

Total runtime (with or without pause-time)

get_time_paused(start_idx=0, end_idx=-1)[source]

Get pause-time between different ticks

last()[source]

Return the time duration of the last tick i.e. time between the last two ticks

pause()[source]

Pause the stopwatch (Ticks are not recorded until resumed)

resume()[source]

Resume

Return type:

Time for which the instance was paused

start()[source]

Start the stopwatch

stop()[source]

Stops the stopwatch

Return type:

Total time (including pause-time)

tick(name=None)[source]

Record a tick

Return type:

Time since the last tick

property time_active
property time_elapsed

Get time elapsed between different ticks

If there are multiple matches for start or end ticks, the following two ticks are selected: - the chronologically first matching tick for start - the chronologically last matching tick for end

Parameters:

start_key (int or str)

exclude_pause: bool

If True, pause-time is not counted. The default is True.

Return type:

Total runtime (with or without pause-time)

property time_paused

Get pause-time between different ticks

property time_total