DebugTimes

class lib.utils.DebugTimes(show_min: bool = True, show_mean: bool = True, show_max: bool = True)

Bases: object

A simple tool to help debug timings.

Parameters:
  • min – Display minimum time taken in summary stats. Default: True

  • mean – Display mean time taken in summary stats. Default: True

  • max – Display maximum time taken in summary stats. Default: True

  • show_min (bool)

  • show_mean (bool)

  • show_max (bool)

Example

>>> from lib.utils import DebugTimes
>>> debug_times = DebugTimes()
>>> debug_times.step_start("step 1")
>>> # do something here
>>> debug_times.step_end("step 1")
>>> debug_times.summary()
----------------------------------
Step             Count   Min
----------------------------------
step 1           1       0.000000

Methods Summary

step_end(name[, record])

Stop the timer and record elapsed time for the given step name.

step_start(name[, record])

Start the timer for the given step name.

summary([decimal_places, interval])

Print a summary of step times.

Methods Documentation

step_end(name: str, record: bool = True) None

Stop the timer and record elapsed time for the given step name.

Parameters:
  • name (str) – The name of the step to end the timer for

  • record (bool) – True to record the step time, False to not record it. Used for when you have conditional code to time, but do not want to insert if/else statements in the code. Default: True

Return type:

None

Example

>>> from lib.util import DebugTimes
>>> debug_times = DebugTimes()
>>> debug_times.step_start("Example Step")
>>> # do something here
>>> debug_times.step_end("Example Step")
step_start(name: str, record: bool = True) None

Start the timer for the given step name.

Parameters:
  • name (str) – The name of the step to start the timer for

  • record (bool) – True to record the step time, False to not record it. Used for when you have conditional code to time, but do not want to insert if/else statements in the code. Default: True

Return type:

None

Example

>>> from lib.util import DebugTimes
>>> debug_times = DebugTimes()
>>> debug_times.step_start("Example Step")
>>> # do something here
>>> debug_times.step_end("Example Step")
summary(decimal_places: int = 6, interval: int = 1) None

Print a summary of step times.

Parameters:
  • decimal_places (int) – The number of decimal places to display the summary elapsed times to. Default: 6

  • interval (int) – How many times summary must be called before printing to console. Default: 1

Return type:

None

Example

>>> from lib.utils import DebugTimes
>>> debug = DebugTimes()
>>> debug.step_start("test")
>>> time.sleep(0.5)
>>> debug.step_end("test")
>>> debug.summary()
----------------------------------
Step             Count   Min
----------------------------------
test             1       0.500000
step_end(name: str, record: bool = True) None

Stop the timer and record elapsed time for the given step name.

Parameters:
  • name (str) – The name of the step to end the timer for

  • record (bool) – True to record the step time, False to not record it. Used for when you have conditional code to time, but do not want to insert if/else statements in the code. Default: True

Return type:

None

Example

>>> from lib.util import DebugTimes
>>> debug_times = DebugTimes()
>>> debug_times.step_start("Example Step")
>>> # do something here
>>> debug_times.step_end("Example Step")
step_start(name: str, record: bool = True) None

Start the timer for the given step name.

Parameters:
  • name (str) – The name of the step to start the timer for

  • record (bool) – True to record the step time, False to not record it. Used for when you have conditional code to time, but do not want to insert if/else statements in the code. Default: True

Return type:

None

Example

>>> from lib.util import DebugTimes
>>> debug_times = DebugTimes()
>>> debug_times.step_start("Example Step")
>>> # do something here
>>> debug_times.step_end("Example Step")
summary(decimal_places: int = 6, interval: int = 1) None

Print a summary of step times.

Parameters:
  • decimal_places (int) – The number of decimal places to display the summary elapsed times to. Default: 6

  • interval (int) – How many times summary must be called before printing to console. Default: 1

Return type:

None

Example

>>> from lib.utils import DebugTimes
>>> debug = DebugTimes()
>>> debug.step_start("test")
>>> time.sleep(0.5)
>>> debug.step_end("test")
>>> debug.summary()
----------------------------------
Step             Count   Min
----------------------------------
test             1       0.500000