pytimings.timer

Main module.

Module Contents

Classes

TimingDelta

Elapsed wall/system/user time for a section, all in seconds.

TimingData

Timings

Functions

scoped_timing(→ collections.abc.Iterator[None])

Start timer on entering block scope, stop it (and optionally output) on exiting.

cummulative_scoped_timing(→ collections.abc.Iterator[None])

Start timer on entering block scope, stop it (and optionally output) on exiting.

function_timer(→ collections.abc.Callable)

Attributes

THREAD_TIME

WALL_TIME

SYS_TIME

USER_TIME

global_timings

pytimings.timer.THREAD_TIME = 'thread'[source]
pytimings.timer.WALL_TIME = 'wall'[source]
pytimings.timer.SYS_TIME = 'sys'[source]
pytimings.timer.USER_TIME = 'user'[source]
class pytimings.timer.TimingDelta[source]

Bases: NamedTuple

Elapsed wall/system/user time for a section, all in seconds.

wall: float[source]
sys: float[source]
user: float[source]
exception pytimings.timer.NoTimerError(section: str, timings: Timings | None = None, is_unstopped: bool = False)[source]

Bases: Exception

Common base class for all non-exit exceptions.

section[source]
timings[source]
is_unstopped = False[source]
class pytimings.timer.TimingData(name: str)[source]
name[source]
_end_resources = None[source]
_end_times: dict[str, float] | None = None[source]
_process[source]
_start_times[source]
_get() dict[str, float][source]
stop() None[source]
delta() TimingDelta[source]
class pytimings.timer.Timings[source]
_commited_deltas: dict[str, TimingDelta][source]
_known_timers_map: dict[str, tuple[bool, TimingData | None]][source]
extra_data: dict[source]
start(section_name: str) None[source]

set this to begin a named section

stop(section_name: str | None = None) TimingDelta | None[source]

stop named section’s counter or all of them if section_name is None

reset(section_name: str | None = None) None[source]

set elapsed time back to 0 for a given section or all of them if section_name is None

walltime(section_name: str) float[source]

get runtime of section in seconds

add_walltime(section_name: str, time: float) None[source]
delta(section_name: str) TimingDelta[source]

get the full delta tuple

output_files(output_dir: str | pathlib.Path, csv_base: str) pathlib.Path[source]

output all recorded measures to a csv file

output_console() None[source]

output the recorded walltime per section to the console

output_all_measures(out=None) None[source]

output all recorded measures

add_extra_data(data: dict) None[source]

Use this for configuration data that makes the csv more informative.

The data is also rendered in the console output.

pytimings.timer.global_timings[source]
pytimings.timer.scoped_timing(section_name: str, log_function: collections.abc.Callable[[str], None] | None = None, timings: Timings | None = None, format: str = '') collections.abc.Iterator[None][source]

Start timer on entering block scope, stop it (and optionally output) on exiting.

The printout will only show walltime for the current scope. See pytimings.timer.cummulative_scoped_timing() for a version with cummulative output.

pytimings.timer.cummulative_scoped_timing(section_name: str, log_function: collections.abc.Callable[[str], None] | None = None, timings: Timings | None = None, format: str = '') collections.abc.Iterator[None][source]

Start timer on entering block scope, stop it (and optionally output) on exiting.

The printout will show the cummulated walltime for all scopes with this section name. See pytimings.timer.scoped_timing() for a version with non-cummulative output.

pytimings.timer.function_timer(section_name: str | None = None, log_function: collections.abc.Callable[[str], None] | None = None, timings: Timings | None = None) collections.abc.Callable[source]