.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/benchmarks/plot_component_batching_speedup.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_gallery_benchmarks_plot_component_batching_speedup.py: Component batching ================== Compare separate field-component requests with the batched API that shares radial and angular intermediates. .. GENERATED FROM PYTHON SOURCE LINES 8-35 .. image-sg:: /gallery/benchmarks/images/sphx_glr_plot_component_batching_speedup_001.png :alt: Three electric-field components :srcset: /gallery/benchmarks/images/sphx_glr_plot_component_batching_speedup_001.png :class: sphx-glr-single-img .. code-block:: Python from PyFiberModes.units import ureg from time import perf_counter import matplotlib.pyplot as plt from PyFiberModes import HE11 from PyFiberModes.fiber import load_fiber fiber = load_fiber("SMF28", wavelength=1550e-9 * ureg.meter) components = ("Ex", "Ey", "Ez") separate_field = fiber.get_mode_field(HE11, limit=12e-6 * ureg.meter, n_point=101) start = perf_counter() for component in components: getattr(separate_field, component)() separate_time = perf_counter() - start batched_field = fiber.get_mode_field(HE11, limit=12e-6 * ureg.meter, n_point=101) start = perf_counter() batched_field.get_components(components) batched_time = perf_counter() - start figure, axis = plt.subplots() axis.bar(("Separate calls", "Batched request"), (separate_time, batched_time)) axis.set(ylabel="Elapsed time [s]", title="Three electric-field components") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.190 seconds) .. _sphx_glr_download_gallery_benchmarks_plot_component_batching_speedup.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_component_batching_speedup.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_component_batching_speedup.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_component_batching_speedup.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_