3
3
# Licensed under the terms of the BSD 3-Clause
4
4
# (see plotpy/LICENSE for details)
5
5
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
+ """
7
30
8
31
import time
9
32
10
33
import guidata
11
34
import numpy as np
35
+ import pytest
36
+ from guidata .env import execenv
12
37
from guidata .qthelpers import qt_app_context
13
38
from guidata .widgets import about
14
39
from qtpy import QtWidgets as QW
@@ -23,6 +48,17 @@ class BaseBM:
23
48
MAKE_FUNC = make .curve # to be overriden in subclasses
24
49
WIN_TYPE = "auto"
25
50
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
+
26
62
def __init__ (self , name , nsamples , ** options ):
27
63
self .name = name
28
64
self .nsamples = int (nsamples )
@@ -49,16 +85,19 @@ def start(self):
49
85
QW .QApplication .processEvents ()
50
86
plot = win .manager .get_plot ()
51
87
52
- # Create item (ignore this step in benchmark result!)
88
+ # Create item
53
89
self .make_item ()
54
90
55
91
# Benchmarking
56
92
t0 = time .time ()
57
93
self .add_to_plot (plot )
58
- print (self .name + ":" )
59
- print (" N = {}" .format (self .nsamples ))
60
94
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
+
62
101
return win
63
102
64
103
@@ -122,13 +161,11 @@ def compute_data(self):
122
161
return x , y , z
123
162
124
163
164
+ @pytest .mark .skip (reason = "Not relevant in automated test suite" )
125
165
def test_benchmarks ():
126
166
"""Run benchmark"""
127
167
# 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 ()
132
169
133
170
_app = guidata .qapplication ()
134
171
@@ -141,7 +178,7 @@ def test_benchmarks():
141
178
CurveBM ("Curve with sticks" , 1e6 , curvestyle = "Sticks" ),
142
179
ErrorBarBM ("Error bar curve (vertical bars only)" , 1e4 ),
143
180
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 ),
145
182
PColorBM ("Polar pcolor" , 1e3 ),
146
183
ImageBM ("Simple image" , 7e3 , interpolation = "antialiasing" ),
147
184
):
0 commit comments