Skip to content

Commit e1f91cd

Browse files
committed
Update performance thresholds
1 parent d8924c5 commit e1f91cd

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

packages/python/plotly/plotly/tests/test_core/test_graph_objs/test_performance.py

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import time
22
import numpy as np
33
import plotly.graph_objs as go
4+
import pytest
45

56
np.random.seed(1)
67

@@ -14,14 +15,18 @@ def test_performance_b64_scatter3d():
1415
c = np.random.randint(size=N, low=-10, high=10, dtype="int8")
1516

1617
# Test the performance with lists
18+
x_list = x.tolist()
19+
y_list = y.tolist()
20+
z_list = z.tolist()
21+
c_list = c.tolist()
1722
list_start = time.time()
1823
fig = go.Figure(
1924
data=[
2025
go.Scatter3d(
21-
x=x.tolist(),
22-
y=y.tolist(),
23-
z=z.tolist(),
24-
marker=dict(color=c.tolist()),
26+
x=x_list,
27+
y=y_list,
28+
z=z_list,
29+
marker=dict(color=c_list),
2530
mode="markers",
2631
opacity=0.2,
2732
)
@@ -41,31 +46,46 @@ def test_performance_b64_scatter3d():
4146
)
4247
np_time_elapsed = time.time() - np_start
4348

44-
# np should be faster than raw
45-
assert (np_time_elapsed / list_time_elapsed) < 0.75
49+
# np should be faster than lists
50+
assert (np_time_elapsed / list_time_elapsed) < 0.005
4651

4752

4853
def test_performance_b64_float64():
4954
np_arr_1 = np.random.random(10000)
5055
np_arr_2 = np.random.random(10000)
56+
list_1 = np_arr_1.tolist()
57+
list_2 = np_arr_2.tolist()
5158

5259
# Test the performance of the base64 arrays
5360
np_start = time.time()
5461
fig = go.Scatter(x=np_arr_1, y=np_arr_2)
5562
np_time_elapsed = time.time() - np_start
5663

57-
# Test the performance of the raw arrays
64+
# Test the performance of the normal lists
5865
list_start = time.time()
59-
fig = go.Scatter(x=np_arr_1.tolist(), y=np_arr_2.tolist())
66+
fig = go.Scatter(x=list_1, y=list_2)
6067
list_time_elapsed = time.time() - list_start
6168

62-
# np should be faster than raw
63-
assert (np_time_elapsed / list_time_elapsed) < 0.75
69+
# np should be faster than lists
70+
assert (np_time_elapsed / list_time_elapsed) < 0.3
6471

6572

66-
def test_size_performance_b64_uint8():
67-
np_arr_1 = (np.random.random(100000) * 256).astype("uint8")
68-
np_arr_2 = (np.random.random(100000) * 256).astype("uint8")
73+
DTYPE_TEST_CASES = [
74+
(
75+
"uint8", # dtype
76+
256, # max_val
77+
400000 # difference threshold
78+
),
79+
(
80+
'uint32',
81+
2**32,
82+
900000
83+
)
84+
]
85+
@pytest.mark.parametrize('dtype, max_val, expected_size_difference', DTYPE_TEST_CASES)
86+
def test_size_performance_b64_uint8(dtype, max_val, expected_size_difference):
87+
np_arr_1 = (np.random.random(100000) * max_val).astype(dtype)
88+
np_arr_2 = (np.random.random(100000) * max_val).astype(dtype)
6989

7090
# Measure the size of figures with numpy arrays
7191
fig_np = go.Scatter(x=np_arr_1, y=np_arr_2)
@@ -75,5 +95,5 @@ def test_size_performance_b64_uint8():
7595
fig_list = go.Scatter(x=np_arr_1.tolist(), y=np_arr_2.tolist())
7696
size_list = fig_list.to_json().__sizeof__()
7797

78-
# np should be smaller than raw
79-
assert size_list - size_np > 1000
98+
# np should be smaller than lists
99+
assert size_list - size_np > expected_size_difference

0 commit comments

Comments
 (0)