.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/benchmarks/plot_modal_cache_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_modal_cache_speedup.py: Modal-cache speedup =================== Compare the first effective-index solution with a repeated lookup served by the geometry-aware modal cache. .. GENERATED FROM PYTHON SOURCE LINES 8-30 .. image-sg:: /gallery/benchmarks/images/sphx_glr_plot_modal_cache_speedup_001.png :alt: Geometry-aware modal cache :srcset: /gallery/benchmarks/images/sphx_glr_plot_modal_cache_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 LP01 from PyFiberModes.fiber import load_fiber fiber = load_fiber("SMF28", wavelength=1550e-9 * ureg.meter) start = perf_counter() fiber.get_effective_index(LP01) uncached_time = perf_counter() - start start = perf_counter() fiber.get_effective_index(LP01) cached_time = perf_counter() - start figure, axis = plt.subplots() axis.bar(("First solution", "Cached lookup"), (uncached_time, cached_time)) axis.set(ylabel="Elapsed time [s]", title="Geometry-aware modal cache") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.060 seconds) .. _sphx_glr_download_gallery_benchmarks_plot_modal_cache_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_modal_cache_speedup.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_modal_cache_speedup.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_modal_cache_speedup.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_