Skip to content

Commit 98f2541

Browse files
committed
Parametrize functions and lower performance thresholds
1 parent e1f91cd commit 98f2541

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed

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

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,57 +20,67 @@ def test_performance_b64_scatter3d():
2020
z_list = z.tolist()
2121
c_list = c.tolist()
2222
list_start = time.time()
23-
fig = go.Figure(
24-
data=[
25-
go.Scatter3d(
26-
x=x_list,
27-
y=y_list,
28-
z=z_list,
29-
marker=dict(color=c_list),
30-
mode="markers",
31-
opacity=0.2,
32-
)
33-
]
34-
)
23+
fig = go.Figure(data=[go.Scatter3d(
24+
x=x_list,
25+
y=y_list,
26+
z=z_list,
27+
marker=dict(color=c_list),
28+
mode="markers",
29+
opacity=0.2,
30+
)])
31+
fig.show()
3532
list_time_elapsed = time.time() - list_start
3633

3734
# Test the performance with base64 arrays
3835
np_start = time.time()
39-
fig = go.Scatter3d(
36+
fig = go.Figure(data=[go.Scatter3d(
4037
x=x,
4138
y=y,
4239
z=z,
4340
marker=dict(color=c),
4441
mode="markers",
4542
opacity=0.2,
46-
)
43+
)])
44+
fig.show()
4745
np_time_elapsed = time.time() - np_start
4846

4947
# np should be faster than lists
50-
assert (np_time_elapsed / list_time_elapsed) < 0.005
51-
48+
assert (np_time_elapsed / list_time_elapsed) < 0.5
5249

53-
def test_performance_b64_float64():
54-
np_arr_1 = np.random.random(10000)
55-
np_arr_2 = np.random.random(10000)
50+
FLOAT_TEST_CASES = [
51+
(
52+
"float32", # dtype
53+
0.45 # difference threshold
54+
),
55+
(
56+
'float64',
57+
0.55
58+
)
59+
]
60+
@pytest.mark.parametrize('dtype, expected_size_difference', FLOAT_TEST_CASES)
61+
def test_performance_b64_float(dtype, expected_size_difference):
62+
np_arr_1 = np.random.random(10000).astype(dtype)
63+
np_arr_2 = np.random.random(10000).astype(dtype)
5664
list_1 = np_arr_1.tolist()
5765
list_2 = np_arr_2.tolist()
5866

5967
# Test the performance of the base64 arrays
6068
np_start = time.time()
61-
fig = go.Scatter(x=np_arr_1, y=np_arr_2)
69+
fig = go.Figure(data=[go.Scatter(x=np_arr_1, y=np_arr_2)])
70+
fig.show()
6271
np_time_elapsed = time.time() - np_start
6372

6473
# Test the performance of the normal lists
6574
list_start = time.time()
66-
fig = go.Scatter(x=list_1, y=list_2)
75+
fig = go.Figure(data=[go.Scatter(x=list_1, y=list_2)])
76+
fig.show()
6777
list_time_elapsed = time.time() - list_start
6878

6979
# np should be faster than lists
70-
assert (np_time_elapsed / list_time_elapsed) < 0.3
80+
assert (np_time_elapsed / list_time_elapsed) < expected_size_difference
7181

7282

73-
DTYPE_TEST_CASES = [
83+
INT_SIZE_PERFORMANCE_TEST_CASES = [
7484
(
7585
"uint8", # dtype
7686
256, # max_val
@@ -82,8 +92,8 @@ def test_performance_b64_float64():
8292
900000
8393
)
8494
]
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):
95+
@pytest.mark.parametrize('dtype, max_val, expected_size_difference', INT_SIZE_PERFORMANCE_TEST_CASES)
96+
def test_size_performance_b64_int(dtype, max_val, expected_size_difference):
8797
np_arr_1 = (np.random.random(100000) * max_val).astype(dtype)
8898
np_arr_2 = (np.random.random(100000) * max_val).astype(dtype)
8999

0 commit comments

Comments
 (0)