Skip to content

Commit 04d1321

Browse files
committed
Added benchmark script (removed from test suite)
1 parent 9b1805f commit 04d1321

File tree

5 files changed

+78
-12
lines changed

5 files changed

+78
-12
lines changed

plotpy/tests/benchmarks/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Licensed under the terms of the BSD 3-Clause
4+
# (see plotpy/LICENSE for details)
5+
6+
"""
7+
plotpy benchmarks
8+
=================
9+
"""
10+
11+
from .test_benchmarks import test_benchmarks
12+
13+
14+
def run() -> None:
15+
"""Run plotpy benchmarks"""
16+
test_benchmarks()
17+
18+
19+
if __name__ == "__main__":
20+
run()

plotpy/tests/benchmarks/test_benchmarks.py

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,37 @@
33
# Licensed under the terms of the BSD 3-Clause
44
# (see plotpy/LICENSE for details)
55

6-
"""plotpy plot benchmarking"""
6+
"""
7+
PlotPy plot benchmark
8+
---------------------
9+
10+
This script benchmarks PlotPy plotting features.
11+
12+
13+
Results obtained with PlotPy v2.3.5 on Windows 11 with a i5-1335U CPU @ 1.30 GHz:
14+
15+
.. code-block:: none
16+
17+
PlotPy plot benchmark [Python 3.12.3 64 bits, Qt 5.15.2, PyQt 5.15.10 on Windows]
18+
19+
N | ∆t (ms) | Description
20+
--------------------------------------------------------------------------------
21+
5e+06 | 215 | Simple curve
22+
2e+05 | 774 | Curve with markers
23+
1e+06 | 2411 | Curve with sticks
24+
1e+04 | 2025 | Error bar curve (vertical bars only)
25+
1e+04 | 198 | Error bar curve (horizontal and vertical bars)
26+
1e+06 | 105 | Simple histogram
27+
1e+03 | 722 | Polar pcolor
28+
7e+03 | 902 | Simple image
29+
"""
730

831
import time
932

1033
import guidata
1134
import numpy as np
35+
import pytest
36+
from guidata.env import execenv
1237
from guidata.qthelpers import qt_app_context
1338
from guidata.widgets import about
1439
from qtpy import QtWidgets as QW
@@ -23,6 +48,17 @@ class BaseBM:
2348
MAKE_FUNC = make.curve # to be overriden in subclasses
2449
WIN_TYPE = "auto"
2550

51+
@classmethod
52+
def print_header(cls):
53+
"""Print header for benchmark results"""
54+
execenv.print(f"PlotPy plot benchmark [{about.get_python_libs_infos()}]")
55+
execenv.print()
56+
table_header = (
57+
"N".rjust(10) + " | " + "∆t (ms)".rjust(7) + " | " + "Description"
58+
).ljust(80)
59+
execenv.print(table_header)
60+
execenv.print("-" * len(table_header))
61+
2662
def __init__(self, name, nsamples, **options):
2763
self.name = name
2864
self.nsamples = int(nsamples)
@@ -49,16 +85,19 @@ def start(self):
4985
QW.QApplication.processEvents()
5086
plot = win.manager.get_plot()
5187

52-
# Create item (ignore this step in benchmark result!)
88+
# Create item
5389
self.make_item()
5490

5591
# Benchmarking
5692
t0 = time.time()
5793
self.add_to_plot(plot)
58-
print(self.name + ":")
59-
print(" N = {}".format(self.nsamples))
6094
plot.replot() # Force replot
61-
print(" dt = {} ms".format((time.time() - t0) * 1e3))
95+
QW.QApplication.processEvents()
96+
dt = (time.time() - t0) * 1e3
97+
98+
row = f"{self.nsamples:10.0e} | {int(dt):7} | {self.name}"
99+
execenv.print(row)
100+
62101
return win
63102

64103

@@ -122,13 +161,11 @@ def compute_data(self):
122161
return x, y, z
123162

124163

164+
@pytest.mark.skip(reason="Not relevant in automated test suite")
125165
def test_benchmarks():
126166
"""Run benchmark"""
127167
# Print(informations banner)
128-
title = f"PlotPy plot benchmark [{about.get_python_libs_infos()}]"
129-
print(title)
130-
print("-" * len(title))
131-
print()
168+
BaseBM.print_header()
132169

133170
_app = guidata.qapplication()
134171

@@ -141,7 +178,7 @@ def test_benchmarks():
141178
CurveBM("Curve with sticks", 1e6, curvestyle="Sticks"),
142179
ErrorBarBM("Error bar curve (vertical bars only)", 1e4),
143180
ErrorBarBM("Error bar curve (horizontal and vertical bars)", 1e4, dx=True),
144-
HistogramBM("Simple histogram", 1e6, bins=int(1e5)),
181+
HistogramBM("Simple histogram", 1e6, bins=10000),
145182
PColorBM("Polar pcolor", 1e3),
146183
ImageBM("Simple image", 7e3, interpolation="antialiasing"),
147184
):

plotpy/tests/benchmarks/test_bigimages.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# guitest: show
99

1010
import numpy as np
11+
import pytest
1112
from guidata.qthelpers import qt_app_context
1213

1314
from plotpy.builder import make
@@ -28,6 +29,7 @@ def compute_image(i, N=7500, M=1750):
2829
return (np.random.rand(N, M) * 65536).astype(np.int16)
2930

3031

32+
@pytest.mark.skip(reason="Not relevant in automated test suite")
3133
def test_bigimages():
3234
"""Test Bigimages"""
3335
with qt_app_context(exec_loop=True):

plotpy/tests/benchmarks/test_loadtest.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# guitest: show
99

1010
import numpy as np
11+
import pytest
1112
from guidata.qthelpers import qt_app_context
1213

1314
# import cProfile
@@ -72,9 +73,10 @@ def refresh(self):
7273
QW.QApplication.processEvents()
7374

7475

75-
if __name__ == "__main__":
76+
@pytest.mark.skip(reason="Not relevant in automated test suite")
77+
def test_loadtest():
78+
"""Run load test"""
7679
with qt_app_context(exec_loop=True):
77-
app = QW.QApplication([])
7880
# import time
7981
# t0 = time.time()
8082
# with cProfile.Profile() as pr:
@@ -87,3 +89,7 @@ def refresh(self):
8789
# stats.sort_stats('cumulative')
8890
# stats.dump_stats('.prof_stats')
8991
# stats.print_stats()
92+
93+
94+
if __name__ == "__main__":
95+
test_loadtest()

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Documentation = "https://plotpy.readthedocs.io/en/latest/"
5959

6060
[project.gui-scripts]
6161
plotpy-tests = "plotpy.tests:run"
62+
plotpy-benchmarks = "plotpy.tests.benchmarks:run"
6263

6364
[project.optional-dependencies]
6465
dev = ["ruff", "pylint", "Coverage", "Cython"]

0 commit comments

Comments
 (0)