capytaine.tools.timer module

A simple timer class used to measure the time spent in various parts of the BEM solver.

class capytaine.tools.timer.Timer(*, default_tags=None)[source]

Bases: object

A timer class that can be used as context manager or as decorator using wraps_function method. Several timing measurement can be nested.

Variables:
  • timings (List[Dict]]) – List of records of each timing measurement. The record is a dict with a ‘timing’ key and any number of other metadata keys.

  • default_tags (Optional[Dict]) – Tags added to all the timing measurements.

  • _start_times (List[float]) – Start times of the ongoing timing measurements.

Example

::

from time import sleep # For testing

timer = Timer()

with timer(tag=”run 1”):

sleep(1.0)

print(timer.total) # 1.0…

@timer.wraps_function(tag=”run function”) def my_function():

sleep(0.5)

my_function() print(timer.total) # 1.5… my_function() print(timer.total) # 2.0…

with timer(tag=”outer”):

sleep(0.3) with timer(tag=”inner”):

sleep(0.3)

sleep(0.3)

add_data_from_other_timer(other, **supplementary_tags)[source]
as_dataframe()[source]
property total
wraps_function(**tags)[source]