.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/benchmarks/reproducible_parameter_sweep.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_reproducible_parameter_sweep.py: Reproducible parameter-sweep benchmark ====================================== Benchmark a fixed PyMieSim parameter grid while recording environment metadata. The script is deterministic; runtime values are machine-dependent and should be compared only under the same environment. .. GENERATED FROM PYTHON SOURCE LINES 9-50 .. rst-class:: sphx-glr-script-out .. code-block:: none Python: 3.11.16 Platform: Linux-6.17.0-1022-azure-x86_64-with-glibc2.39 PyMieSim grid: [1, 1, 1, 1, 100, 1, 1] Results: 100 Median runtime: 0.001444 s All timings: [0.001465, 0.001444, 0.001452, 0.001435, 0.001442] | .. code-block:: Python import platform import statistics import time import numpy as np from PyMieSim import Experiment, GaussianSet, PolarizationSet, SphereSet, ureg def build_experiment(size: int = 100) -> Experiment: source = GaussianSet( wavelength=[600] * ureg.nanometer, polarization=PolarizationSet(angles=[0] * ureg.degree), optical_power=[1e-3] * ureg.watt, numerical_aperture=[0.2], ) scatterer = SphereSet( diameter=np.linspace(100, 1000, size) * ureg.nanometer, material=[1.5], medium=[1.0], ) return Experiment(scatterer_set=scatterer, source_set=source) experiment = build_experiment() for _ in range(2): experiment.get("Qsca").as_numpy() timings = [] for _ in range(5): start = time.perf_counter() values = experiment.get("Qsca").as_numpy() timings.append(time.perf_counter() - start) print(f"Python: {platform.python_version()}") print(f"Platform: {platform.platform()}") print(f"PyMieSim grid: {experiment.array_shape}") print(f"Results: {np.asarray(values).size}") print(f"Median runtime: {statistics.median(timings):.6f} s") print(f"All timings: {[round(value, 6) for value in timings]}") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.022 seconds) .. _sphx_glr_download_gallery_benchmarks_reproducible_parameter_sweep.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: reproducible_parameter_sweep.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: reproducible_parameter_sweep.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: reproducible_parameter_sweep.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_