.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/advanced-usage.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_advanced-usage.py: ====================== Advanced Usage Example ====================== This is a advanced usage example of the `stopuhr` package. .. GENERATED FROM PYTHON SOURCE LINES 12-13 Also print out function arguments .. GENERATED FROM PYTHON SOURCE LINES 13-25 .. code-block:: Python import time from stopuhr import stopwatch @stopwatch.f("Sleeping") def sleep(seconds: float): time.sleep(seconds) sleep(0.1) .. rst-class:: sphx-glr-script-out .. code-block:: none Sleeping (with seconds=0.1) took 0.10s .. GENERATED FROM PYTHON SOURCE LINES 26-28 If some parameters should not be printed, we can use the `print_kwargs` argument.to select which ones should be printed. .. GENERATED FROM PYTHON SOURCE LINES 28-38 .. code-block:: Python @stopwatch.f("Sleeping", print_kwargs=["seconds"]) def sleep(seconds: float, other: str): time.sleep(seconds) print(other) sleep(0.1, "Hello") .. rst-class:: sphx-glr-script-out .. code-block:: none Hello Sleeping (with seconds=0.1) took 0.10s .. GENERATED FROM PYTHON SOURCE LINES 39-41 In multi processing situations, we must use a separate `Chronometer` instance for each process. For this, we can use the `merge` or `combine` method to combine the results of multiple `Chronometer` instances. .. GENERATED FROM PYTHON SOURCE LINES 41-61 .. code-block:: Python import stopuhr def simulate_process(): timer = stopuhr.Chronometer() with timer("Sleeping"): time.sleep(0.1) res = 3.14159 return {"result": res, "timer": timer} # We only simulate a multi processing situation here. A real one would be too much overhead. tasks_outputs = [simulate_process() for _ in range(5)] tasks_timer = [task["timer"] for task in tasks_outputs] combined_timer = stopuhr.Chronometer.combine(tasks_timer) combined_timer.summary() .. rst-class:: sphx-glr-script-out .. code-block:: none Sleeping took 0.10s Sleeping took 0.10s Sleeping took 0.10s Sleeping took 0.10s Sleeping took 0.10s Sleeping took 0.10 ± 0.00s (n=5 -> total=0.50s) .. _sphx_glr_download_auto_examples_advanced-usage.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: advanced-usage.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: advanced-usage.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: advanced-usage.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_