spine.utils.stopwatch

Simple stopwatch class to track execution times of various processes.

Classes

Stopwatch()

Simple class to hold timing information for a specific process.

StopwatchManager()

Simple class to organize various time measurements.

Time([wall, cpu])

Simple dataclass to hold time information.

class spine.utils.stopwatch.Time(wall: float | None = None, cpu: float | None = None)[source]

Simple dataclass to hold time information.

wall

Wall time

Type:

float, optional

cpu

CPU time

Type:

float, optional

Attributes:
cpu
wall

Methods

copy()

Returns an independant copy of the object.

current()

Simple function which returns the current time (wall and cpu).

wall: float | None = None
cpu: float | None = None
copy()[source]

Returns an independant copy of the object.

Returns:

Copy of the object

Return type:

Time

classmethod current()[source]

Simple function which returns the current time (wall and cpu).

Returns:

Current time

Return type:

Time

class spine.utils.stopwatch.Stopwatch[source]

Simple class to hold timing information for a specific process.

Attributes:
pause

Time when the stopwatch was last paused.

paused

Whether the stopwatch is currently paused.

running

Whether the stopwatch is currently running.

start

Time when the stopwatch was last started.

stop

Time when the stopwatch was last stopped.

time

Time between the last start and the last stop.

time_sum

Sum of times between all watch starts en stops.

property running

Whether the stopwatch is currently running.

property paused

Whether the stopwatch is currently paused.

property start

Time when the stopwatch was last started.

property stop

Time when the stopwatch was last stopped.

property pause

Time when the stopwatch was last paused.

property time

Time between the last start and the last stop.

property time_sum

Sum of times between all watch starts en stops.

class spine.utils.stopwatch.StopwatchManager[source]

Simple class to organize various time measurements.

Methods

initialize(key)

Initialize one stopwatch.

items()

Get the list of all initialized stopwatch tags and the corresponding Stopwatch object for each of them.

keys()

Get the list of all initialized stopwatch tags.

pause(key)

Temporarily pause a watch for a unique key.

reset([key])

Reset a stopwatch to its initial state.

reset_if_active()

Reset all stopwatches if any tracked watch is still active.

start(key)

Starts a stopwatch for a unique key.

stop(key)

Stops a stopwatch for a unique key.

time(key)

Returns the time recorded since the last start.

time_sum(key)

Returns the sum of times recorded between each start/stop pairs.

times()

Returns the times for each of the stopwatches as a dictionary.

times_sum()

Returns the times for each of the stopwatches as a dictionary.

update(other[, prefix])

Updates this manager with values from another stopwatch manager.

values()

Get the list of all initialized stopwatches.

keys()[source]

Get the list of all initialized stopwatch tags.

Returns:

List of stopwatch names

Return type:

List[str]

values()[source]

Get the list of all initialized stopwatches.

Returns:

List of stopwatch objects

Return type:

List[Stopwatch]

items()[source]

Get the list of all initialized stopwatch tags and the corresponding Stopwatch object for each of them.

Returns:

List of (key, stopwatch) pairs

Return type:

List[Tuple[str, Stopwatch]]

initialize(key)[source]

Initialize one stopwatch. If it’s already been initialized, reset the global counters to 0.

Parameters:

key (Union[str, List[str]]) – Key or list of keys to initialize a Stopwatch for

reset(key=None)[source]

Reset a stopwatch to its initial state.

Parameters:

key (Union[str, List[str]], optional) – Key or list of keys to reset a Stopwatch for. If None, reset all stopwatches.

reset_if_active()[source]

Reset all stopwatches if any tracked watch is still active.

start(key)[source]

Starts a stopwatch for a unique key.

Parameters:

key (Union[str, List[str]]) – Key or list of keys for which to start the clock

stop(key)[source]

Stops a stopwatch for a unique key.

Parameters:

key (str) – Key for which to stop the clock

pause(key)[source]

Temporarily pause a watch for a unique key.

Parameters:

key (str) – Key for which to pause the clock

time(key)[source]

Returns the time recorded since the last start.

Parameters:

key (str) – Key for which to return the time

Returns:

Execution time of one iteration of a process

Return type:

Time

time_sum(key)[source]

Returns the sum of times recorded between each start/stop pairs.

Parameters:

key (str) – Key for which to return the time

Returns:

Execution time of all iterations of a process so far

Return type:

Time

times()[source]

Returns the times for each of the stopwatches as a dictionary.

Returns:

Execution time of one iteration of each process

Return type:

Dict[str, Time]

times_sum()[source]

Returns the times for each of the stopwatches as a dictionary.

Returns:

Execution time of all iterations of each process so far

Return type:

Dict[str, Time]

update(other, prefix=None)[source]

Updates this manager with values from another stopwatch manager.

Parameters:
  • other (StopwatchManager) – Dictionary of execution times from another process

  • prefix (str, optional) – String to prefix the timer key with

Returns:

Combined execution time of all iterations of each process so far

Return type:

Dict[str, Time]