pyquickbench.TimeTrain#

class TimeTrain(path_prefix=None, include_locs=None, include_filename=True, include_lineno=True, include_funname=True, name='', align_toc_names=True, names_reduction=None, global_tictoc_sync=True, ignore_names=None, relative_timings=False)[source]#

Records elapsed time between interest points in code

See Time Trains for usage example.

Parameters:
  • path_prefix (str | None)

  • include_locs (bool | None)

  • include_filename (bool)

  • include_lineno (bool)

  • include_funname (bool)

  • name (str)

  • align_toc_names (bool)

  • names_reduction (str | None)

  • global_tictoc_sync (bool)

  • ignore_names (Iterable[str])

  • relative_timings (bool)

__init__(path_prefix=None, include_locs=None, include_filename=True, include_lineno=True, include_funname=True, name='', align_toc_names=True, names_reduction=None, global_tictoc_sync=True, ignore_names=None, relative_timings=False)[source]#

Returns a TimeTrain

Parameters:
  • path_prefix (str | None, optional) – Path relative to which other paths are to be understood, by default None.

  • include_locs (bool | None, optional) – Whether to include locations in code when printing the TimeTrain, by default None.

  • include_filename (bool, optional) – Whether to include the file name in locations in code when printing the TimeTrain, by default True.

  • include_lineno (bool, optional) – Whether to include the line number in locations in code when printing the TimeTrain, by default True.

  • include_funname (bool, optional) – Whether to include the function name in locations in code when printing the TimeTrain, by default True.

  • name (str, optional) – Name of the TimeTrain, by default ''.

  • align_toc_names (bool, optional) – Whether to align toc names when printing the TimeTrain, by default True.

  • names_reduction (str | None, optional) – Reduction to be applied to tocs that share the same name, by default None.

  • global_tictoc_sync (bool, optional) – Set to True to use a common shared name for synchronization in pyquickbench.TimeTrain.tictoc() or to False to use a specific name for every decorated function. By default True.

  • ignore_names (str | None, optional) – Names to be ignored by print() and pyquickbench.TimeTrain.to_dict(). By default None.

  • relative_timings (bool, optional) – Whether to display relative timings when printing the TimeTrain. Relative timings only sum up to 100% if names_reduction is None or "sum". By default False.

Methods

__init__([path_prefix, include_locs, ...])

Returns a TimeTrain

to_dict([return_first_instance, names_reduction])

Returns time measurements within a TimeTrain as a Python dictionary

toc([name])

Records a new wagon in the TimeTrain.

Attributes

tictoc

Decorates a function to record a new wagon in the TimeTrain before and after each call.

total_time

Returns the total time recorded by the TimeTrain so far.