.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_build/auto_examples/tutorial/04-Error_handling.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__build_auto_examples_tutorial_04-Error_handling.py: Handling errors =============== .. GENERATED FROM PYTHON SOURCE LINES 7-8 By default, :func:`pyquickbench.run_benchmark` will try to benchmark as much as possible even if the callables to be benchmarked throw errors. These errors are caught and the corresponding value in the benchmark is recorded as ``np.nan``, which will in turn show in plots as a missing value. .. GENERATED FROM PYTHON SOURCE LINES 8-44 .. code-block:: Python import pyquickbench def comprehension(n): if n == 1 : raise ValueError('Forbidden value') return ['' for _ in range(n)] def star_operator(n): if n == 8: raise ValueError('Forbidden value') return ['']*n def for_loop_append(n): if n == 32: raise ValueError('Forbidden value') l = [] for _ in range(n): l.append('') all_funs = [ comprehension , star_operator , for_loop_append , ] n_bench = 8 all_sizes = np.array([2**n for n in range(n_bench)]) pyquickbench.run_benchmark( all_sizes , all_funs , show = True , ) .. image-sg:: /_build/auto_examples/tutorial/images/sphx_glr_04-Error_handling_001.png :alt: 04 Error handling :srcset: /_build/auto_examples/tutorial/images/sphx_glr_04-Error_handling_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 76-77 This default can be overriden with the argument ``StopOnExcept`` set to :data:`python:True`. The error is then not caught by :func:`pyquickbench.run_benchmark`, and it is the user's responsibility to handle it. .. GENERATED FROM PYTHON SOURCE LINES 77-86 .. code-block:: Python try: pyquickbench.run_benchmark( all_sizes , all_funs , show = True , StopOnExcept = True , ) except Exception as exc: print(f'Exception thrown: {exc}') .. rst-class:: sphx-glr-script-out .. code-block:: none Exception thrown: Forbidden value .. _sphx_glr_download__build_auto_examples_tutorial_04-Error_handling.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 04-Error_handling.ipynb <04-Error_handling.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 04-Error_handling.py <04-Error_handling.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 04-Error_handling.zip <04-Error_handling.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_