diff --git a/plotpy/tests/benchmarks/__init__.py b/plotpy/tests/benchmarks/__init__.py index e69de29b..30d54314 100644 --- a/plotpy/tests/benchmarks/__init__.py +++ b/plotpy/tests/benchmarks/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# +# Licensed under the terms of the BSD 3-Clause +# (see plotpy/LICENSE for details) + +""" +plotpy benchmarks +================= +""" + +from .test_benchmarks import test_benchmarks + + +def run() -> None: + """Run plotpy benchmarks""" + test_benchmarks() + + +if __name__ == "__main__": + run() diff --git a/plotpy/tests/benchmarks/test_benchmarks.py b/plotpy/tests/benchmarks/test_benchmarks.py index bd6bb3b3..93afa2e3 100644 --- a/plotpy/tests/benchmarks/test_benchmarks.py +++ b/plotpy/tests/benchmarks/test_benchmarks.py @@ -3,12 +3,37 @@ # Licensed under the terms of the BSD 3-Clause # (see plotpy/LICENSE for details) -"""plotpy plot benchmarking""" +""" +PlotPy plot benchmark +--------------------- + +This script benchmarks PlotPy plotting features. + + +Results obtained with PlotPy v2.3.5 on Windows 11 with a i5-1335U CPU @ 1.30 GHz: + +.. code-block:: none + + PlotPy plot benchmark [Python 3.12.3 64 bits, Qt 5.15.2, PyQt 5.15.10 on Windows] + + N | ∆t (ms) | Description + -------------------------------------------------------------------------------- + 5e+06 | 215 | Simple curve + 2e+05 | 774 | Curve with markers + 1e+06 | 2411 | Curve with sticks + 1e+04 | 2025 | Error bar curve (vertical bars only) + 1e+04 | 198 | Error bar curve (horizontal and vertical bars) + 1e+06 | 105 | Simple histogram + 1e+03 | 722 | Polar pcolor + 7e+03 | 902 | Simple image +""" import time import guidata import numpy as np +import pytest +from guidata.env import execenv from guidata.qthelpers import qt_app_context from guidata.widgets import about from qtpy import QtWidgets as QW @@ -23,6 +48,17 @@ class BaseBM: MAKE_FUNC = make.curve # to be overriden in subclasses WIN_TYPE = "auto" + @classmethod + def print_header(cls): + """Print header for benchmark results""" + execenv.print(f"PlotPy plot benchmark [{about.get_python_libs_infos()}]") + execenv.print() + table_header = ( + "N".rjust(10) + " | " + "∆t (ms)".rjust(7) + " | " + "Description" + ).ljust(80) + execenv.print(table_header) + execenv.print("-" * len(table_header)) + def __init__(self, name, nsamples, **options): self.name = name self.nsamples = int(nsamples) @@ -49,16 +85,19 @@ def start(self): QW.QApplication.processEvents() plot = win.manager.get_plot() - # Create item (ignore this step in benchmark result!) + # Create item self.make_item() # Benchmarking t0 = time.time() self.add_to_plot(plot) - print(self.name + ":") - print(" N = {}".format(self.nsamples)) plot.replot() # Force replot - print(" dt = {} ms".format((time.time() - t0) * 1e3)) + QW.QApplication.processEvents() + dt = (time.time() - t0) * 1e3 + + row = f"{self.nsamples:10.0e} | {int(dt):7} | {self.name}" + execenv.print(row) + return win @@ -122,13 +161,11 @@ def compute_data(self): return x, y, z +@pytest.mark.skip(reason="Not relevant in automated test suite") def test_benchmarks(): """Run benchmark""" # Print(informations banner) - title = f"PlotPy plot benchmark [{about.get_python_libs_infos()}]" - print(title) - print("-" * len(title)) - print() + BaseBM.print_header() _app = guidata.qapplication() @@ -141,7 +178,7 @@ def test_benchmarks(): CurveBM("Curve with sticks", 1e6, curvestyle="Sticks"), ErrorBarBM("Error bar curve (vertical bars only)", 1e4), ErrorBarBM("Error bar curve (horizontal and vertical bars)", 1e4, dx=True), - HistogramBM("Simple histogram", 1e6, bins=int(1e5)), + HistogramBM("Simple histogram", 1e6, bins=10000), PColorBM("Polar pcolor", 1e3), ImageBM("Simple image", 7e3, interpolation="antialiasing"), ): diff --git a/plotpy/tests/benchmarks/test_bigimages.py b/plotpy/tests/benchmarks/test_bigimages.py index fedbbcea..4eeab8ca 100644 --- a/plotpy/tests/benchmarks/test_bigimages.py +++ b/plotpy/tests/benchmarks/test_bigimages.py @@ -8,6 +8,7 @@ # guitest: show import numpy as np +import pytest from guidata.qthelpers import qt_app_context from plotpy.builder import make @@ -28,6 +29,7 @@ def compute_image(i, N=7500, M=1750): return (np.random.rand(N, M) * 65536).astype(np.int16) +@pytest.mark.skip(reason="Not relevant in automated test suite") def test_bigimages(): """Test Bigimages""" with qt_app_context(exec_loop=True): diff --git a/plotpy/tests/benchmarks/test_loadtest.py b/plotpy/tests/benchmarks/test_loadtest.py index 749bdb53..12865f5d 100644 --- a/plotpy/tests/benchmarks/test_loadtest.py +++ b/plotpy/tests/benchmarks/test_loadtest.py @@ -8,6 +8,7 @@ # guitest: show import numpy as np +import pytest from guidata.qthelpers import qt_app_context # import cProfile @@ -72,9 +73,10 @@ def refresh(self): QW.QApplication.processEvents() -if __name__ == "__main__": +@pytest.mark.skip(reason="Not relevant in automated test suite") +def test_loadtest(): + """Run load test""" with qt_app_context(exec_loop=True): - app = QW.QApplication([]) # import time # t0 = time.time() # with cProfile.Profile() as pr: @@ -87,3 +89,7 @@ def refresh(self): # stats.sort_stats('cumulative') # stats.dump_stats('.prof_stats') # stats.print_stats() + + +if __name__ == "__main__": + test_loadtest() diff --git a/pyproject.toml b/pyproject.toml index 34e69369..a60683ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,6 +59,7 @@ Documentation = "https://plotpy.readthedocs.io/en/latest/" [project.gui-scripts] plotpy-tests = "plotpy.tests:run" +plotpy-benchmarks = "plotpy.tests.benchmarks:run" [project.optional-dependencies] dev = ["ruff", "pylint", "Coverage", "Cython"]