Skip to content

Commit

Permalink
Added benchmark script (removed from test suite)
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreRaybaut committed Jun 21, 2024
1 parent 9b1805f commit 04d1321
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 12 deletions.
20 changes: 20 additions & 0 deletions plotpy/tests/benchmarks/__init__.py
Original file line number Diff line number Diff line change
@@ -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()
57 changes: 47 additions & 10 deletions plotpy/tests/benchmarks/test_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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


Expand Down Expand Up @@ -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()

Expand All @@ -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"),
):
Expand Down
2 changes: 2 additions & 0 deletions plotpy/tests/benchmarks/test_bigimages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# guitest: show

import numpy as np
import pytest
from guidata.qthelpers import qt_app_context

from plotpy.builder import make
Expand All @@ -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):
Expand Down
10 changes: 8 additions & 2 deletions plotpy/tests/benchmarks/test_loadtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# guitest: show

import numpy as np
import pytest
from guidata.qthelpers import qt_app_context

# import cProfile
Expand Down Expand Up @@ -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:
Expand All @@ -87,3 +89,7 @@ def refresh(self):
# stats.sort_stats('cumulative')
# stats.dump_stats('.prof_stats')
# stats.print_stats()


if __name__ == "__main__":
test_loadtest()
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 04d1321

Please sign in to comment.