Skip to content

Commit 8fe3174

Browse files
committed
Add: implement benchmark tests for curve rendering with large datasets
1 parent bbe60bb commit 8fe3174

File tree

2 files changed

+92
-3
lines changed

2 files changed

+92
-3
lines changed

plotpy/builder/curvemarker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __set_baseparam(
7777
param: CurveParam | MarkerParam,
7878
color: str | None = None,
7979
linestyle: str | None = None,
80-
linewidth: int | None = None,
80+
linewidth: float | None = None,
8181
marker: str | None = None,
8282
markersize: int | None = None,
8383
markerfacecolor: str | None = None,
@@ -116,7 +116,7 @@ def __set_param(
116116
title: str | None = None,
117117
color: str | None = None,
118118
linestyle: str | None = None,
119-
linewidth: int | None = None,
119+
linewidth: float | None = None,
120120
marker: str | None = None,
121121
markersize: int | None = None,
122122
markerfacecolor: str | None = None,
@@ -313,7 +313,7 @@ def curve(
313313
title: str = "",
314314
color: str | None = None,
315315
linestyle: str | None = None,
316-
linewidth: int | None = None,
316+
linewidth: float | None = None,
317317
marker: str | None = None,
318318
markersize: int | None = None,
319319
markerfacecolor: str | None = None,
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Licensed under the terms of the BSD 3-Clause
4+
# (see plotpy/LICENSE for details)
5+
6+
"""Curve plotting test with large datasets"""
7+
8+
# guitest: show
9+
10+
import timeit
11+
12+
import numpy as np
13+
import pytest
14+
from guidata.qthelpers import qt_app_context
15+
from qtpy import QtWidgets as QW
16+
17+
from plotpy.builder import make
18+
from plotpy.tests import vistools as ptv
19+
20+
21+
def __create_curve(npts: int, linewidth: float):
22+
"""Create a curve with random data"""
23+
x = np.linspace(-10, 10, npts)
24+
y = np.random.normal(size=npts)
25+
curve = make.curve(x, y, color="g", linewidth=linewidth)
26+
return curve
27+
28+
29+
def __show_curve(curve, benchmark: bool = False):
30+
"""Show the curve in a plot window"""
31+
with qt_app_context(exec_loop=not benchmark):
32+
_win = ptv.show_items(
33+
[curve],
34+
wintitle=test_curve_rendering_performance.__doc__,
35+
title="Curves",
36+
plot_type="curve",
37+
disable_readonly_for_items=False,
38+
)
39+
if benchmark:
40+
QW.QApplication.processEvents()
41+
return _win
42+
43+
44+
@pytest.mark.skip(reason="Not relevant in automated test suite")
45+
def test_interactive_curve_rendering(npts: int = 500000, linewidth: float = 1.0):
46+
"""Interactive test for curve rendering with large datasets"""
47+
curve = __create_curve(npts, linewidth)
48+
_win = __show_curve(curve, benchmark=False)
49+
50+
51+
@pytest.mark.skip(reason="Not relevant in automated test suite")
52+
def test_curve_rendering_performance(npts: int = 500000, linewidth: float = 1.0):
53+
"""Test curve rendering performance with large datasets"""
54+
curve = __create_curve(npts, linewidth)
55+
56+
# Show once before benchmarking
57+
_win = __show_curve(curve, benchmark=True)
58+
59+
# Benchmark with multiple runs
60+
n_runs = 5
61+
times = []
62+
63+
print("Benchmarking in progress", end="")
64+
for i in range(n_runs):
65+
start_time = timeit.default_timer()
66+
_win = __show_curve(curve, benchmark=True)
67+
elapsed_time = timeit.default_timer() - start_time
68+
times.append(elapsed_time)
69+
print(".", end="", flush=True)
70+
print(" done.")
71+
72+
# Display statistics
73+
print(
74+
f"Results ({n_runs} runs): {np.mean(times):.4f} ± {np.std(times):.4f} seconds"
75+
)
76+
77+
78+
if __name__ == "__main__":
79+
# test_interactive_curve_rendering(10000, 2.0, False)
80+
# Test with different linewidths and antialiasing settings
81+
print("\n" + "=" * 70)
82+
print("Curve Rendering Performance Benchmark")
83+
print("=" * 70)
84+
85+
print("\n--- Test 1: linewidth=1.0 ---")
86+
test_curve_rendering_performance(10000, 1.0)
87+
88+
print("\n--- Test 2: linewidth=2.0 ---")
89+
test_curve_rendering_performance(10000, 2.0)

0 commit comments

Comments
 (0)