5
5
import pytest
6
6
7
7
np .random .seed (1 )
8
-
8
+ pio . renderers . default = 'png'
9
9
10
10
def test_performance_b64_scatter3d ():
11
- N = 10000
11
+ N = 50000
12
12
print (pio .renderers )
13
13
14
14
x = np .random .randn (N )
@@ -34,7 +34,7 @@ def test_performance_b64_scatter3d():
34
34
)
35
35
]
36
36
)
37
- fig .show (renderer = "png" , engine = "kaleido" )
37
+ fig .show (engine = "kaleido" )
38
38
list_time_elapsed = time .time () - list_start
39
39
40
40
# Test the performance with base64 arrays
@@ -51,63 +51,63 @@ def test_performance_b64_scatter3d():
51
51
)
52
52
]
53
53
)
54
- fig .show (renderer = "png" , engine = "kaleido" )
54
+ fig .show (engine = "kaleido" )
55
55
56
56
np_time_elapsed = time .time () - np_start
57
57
58
58
# np should be faster than lists
59
59
assert (np_time_elapsed / list_time_elapsed ) < 0.7
60
60
61
61
62
- # FLOAT_TEST_CASES = [
63
- # ("float32", 100000, 0.35 ), # dtype # difference threshold
64
- # ("float64", 100000, 0.4 ),
65
- # ]
62
+ FLOAT_TEST_CASES = [
63
+ ("float32" , 100000 , 0.9 ), # dtype # difference threshold
64
+ ("float64" , 100000 , 0.9 ),
65
+ ]
66
66
67
67
68
- # @pytest.mark.parametrize("dtype, count, expected_size_difference", FLOAT_TEST_CASES)
69
- # def test_performance_b64_float(dtype, count, expected_size_difference):
70
- # np_arr_1 = np.random.random(count).astype(dtype)
71
- # np_arr_2 = np.random.random(count).astype(dtype)
72
- # list_1 = np_arr_1.tolist()
73
- # list_2 = np_arr_2.tolist()
68
+ @pytest .mark .parametrize ("dtype, count, expected_size_difference" , FLOAT_TEST_CASES )
69
+ def test_performance_b64_float (dtype , count , expected_size_difference ):
70
+ np_arr_1 = np .random .random (count ).astype (dtype )
71
+ np_arr_2 = np .random .random (count ).astype (dtype )
72
+ list_1 = np_arr_1 .tolist ()
73
+ list_2 = np_arr_2 .tolist ()
74
74
75
- # # Test the performance of the base64 arrays
76
- # np_start = time.time()
77
- # fig = go.Figure(data=[go.Scattergl(x=np_arr_1, y=np_arr_2)])
78
- # fig.show()
79
- # np_time_elapsed = time.time() - np_start
75
+ # Test the performance of the base64 arrays
76
+ np_start = time .time ()
77
+ fig = go .Figure (data = [go .Scattergl (x = np_arr_1 , y = np_arr_2 )])
78
+ fig .show (engine = "kaleido" )
79
+ np_time_elapsed = time .time () - np_start
80
80
81
- # # Test the performance of the normal lists
82
- # list_start = time.time()
83
- # fig = go.Figure(data=[go.Scattergl(x=list_1, y=list_2)])
84
- # fig.show()
85
- # list_time_elapsed = time.time() - list_start
81
+ # Test the performance of the normal lists
82
+ list_start = time .time ()
83
+ fig = go .Figure (data = [go .Scattergl (x = list_1 , y = list_2 )])
84
+ fig .show (engine = "kaleido" )
85
+ list_time_elapsed = time .time () - list_start
86
86
87
- # # np should be faster than lists
88
- # assert (np_time_elapsed / list_time_elapsed) < expected_size_difference
87
+ # np should be faster than lists
88
+ assert (np_time_elapsed / list_time_elapsed ) < expected_size_difference
89
89
90
90
91
- # INT_SIZE_PERFORMANCE_TEST_CASES = [
92
- # ("uint8", 256, 10500, 30000),
93
- # ("uint32", 2**32, 10500, 100000),
94
- # ]
91
+ INT_SIZE_PERFORMANCE_TEST_CASES = [
92
+ ("uint8" , 256 , 10500 , 30000 ),
93
+ ("uint32" , 2 ** 32 , 10500 , 100000 ),
94
+ ]
95
95
96
96
97
- # @pytest.mark.parametrize(
98
- # "dtype, max_value, count, expected_size_difference", INT_SIZE_PERFORMANCE_TEST_CASES
99
- # )
100
- # def test_size_performance_b64_int(dtype, max_value, count, expected_size_difference):
101
- # np_arr_1 = (np.random.random(count) * max_value).astype(dtype)
102
- # np_arr_2 = (np.random.random(count) * max_value).astype(dtype)
97
+ @pytest .mark .parametrize (
98
+ "dtype, max_value, count, expected_size_difference" , INT_SIZE_PERFORMANCE_TEST_CASES
99
+ )
100
+ def test_size_performance_b64_int (dtype , max_value , count , expected_size_difference ):
101
+ np_arr_1 = (np .random .random (count ) * max_value ).astype (dtype )
102
+ np_arr_2 = (np .random .random (count ) * max_value ).astype (dtype )
103
103
104
- # # Measure the size of figures with numpy arrays
105
- # fig_np = go.Scatter(x=np_arr_1, y=np_arr_2)
106
- # size_np = fig_np.to_json().__sizeof__()
104
+ # Measure the size of figures with numpy arrays
105
+ fig_np = go .Scatter (x = np_arr_1 , y = np_arr_2 )
106
+ size_np = fig_np .to_json ().__sizeof__ ()
107
107
108
- # # Measure the size of the figure with normal python lists
109
- # fig_list = go.Scatter(x=np_arr_1.tolist(), y=np_arr_2.tolist())
110
- # size_list = fig_list.to_json().__sizeof__()
108
+ # Measure the size of the figure with normal python lists
109
+ fig_list = go .Scatter (x = np_arr_1 .tolist (), y = np_arr_2 .tolist ())
110
+ size_list = fig_list .to_json ().__sizeof__ ()
111
111
112
- # # np should be smaller than lists
113
- # assert size_list - size_np > expected_size_difference
112
+ # np should be smaller than lists
113
+ assert size_list - size_np > expected_size_difference
0 commit comments