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
831import time
932
1033import guidata
1134import numpy as np
35+ import pytest
36+ from guidata .env import execenv
1237from guidata .qthelpers import qt_app_context
1338from guidata .widgets import about
1439from 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" )
125165def 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 ):
0 commit comments