Skip to content

Commit a508492

Browse files
more tests
1 parent 9adcc8c commit a508492

File tree

1 file changed

+48
-62
lines changed

1 file changed

+48
-62
lines changed

str_performance.ipynb

Lines changed: 48 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 15,
5+
"execution_count": 1,
66
"metadata": {},
77
"outputs": [],
88
"source": [
@@ -14,7 +14,7 @@
1414
},
1515
{
1616
"cell_type": "code",
17-
"execution_count": 16,
17+
"execution_count": 2,
1818
"metadata": {},
1919
"outputs": [
2020
{
@@ -73,7 +73,7 @@
7373
"2 2 C 0.9"
7474
]
7575
},
76-
"execution_count": 16,
76+
"execution_count": 2,
7777
"metadata": {},
7878
"output_type": "execute_result"
7979
}
@@ -85,15 +85,22 @@
8585
" 'value|float': [0.3, 0.5, 0.9]\n",
8686
" }\n",
8787
")\n",
88+
"df2_int = pd.DataFrame(\n",
89+
" {\n",
90+
" 'x|int':[0, 1, 2],\n",
91+
" 'value|float': [0.3, 0.5, 0.9]\n",
92+
" }\n",
93+
")\n",
8894
"str_lookup = Table(df2)\n",
89-
"int_lookup = np.array([0.3, 0.5, 0.9])\n",
95+
"int_lookup = Table(df2_int)\n",
96+
"int_lookup_raw = np.array([0.3, 0.5, 0.9])\n",
9097
"df2_index = df2.reset_index()\n",
9198
"df2_index"
9299
]
93100
},
94101
{
95102
"cell_type": "code",
96-
"execution_count": 17,
103+
"execution_count": 3,
97104
"metadata": {},
98105
"outputs": [],
99106
"source": [
@@ -106,35 +113,22 @@
106113
]
107114
},
108115
{
109-
"cell_type": "code",
110-
"execution_count": 18,
116+
"cell_type": "markdown",
111117
"metadata": {},
112-
"outputs": [
113-
{
114-
"data": {
115-
"text/plain": [
116-
"array([1, 2, 1, 2])"
117-
]
118-
},
119-
"execution_count": 18,
120-
"metadata": {},
121-
"output_type": "execute_result"
122-
}
123-
],
124118
"source": [
125-
"np.tile(np.array([1,2]), 2)"
119+
"## length 100k"
126120
]
127121
},
128122
{
129123
"cell_type": "code",
130-
"execution_count": 19,
124+
"execution_count": 4,
131125
"metadata": {},
132126
"outputs": [
133127
{
134128
"name": "stdout",
135129
"output_type": "stream",
136130
"text": [
137-
"8.8 ms ± 486 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
131+
"12.9 ms ± 1.61 ms per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
138132
]
139133
}
140134
],
@@ -145,107 +139,99 @@
145139
},
146140
{
147141
"cell_type": "code",
148-
"execution_count": 20,
142+
"execution_count": 5,
149143
"metadata": {},
150144
"outputs": [
151145
{
152146
"name": "stdout",
153147
"output_type": "stream",
154148
"text": [
155-
"1.03 s ± 61.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
149+
"360 µs ± 55.7 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)\n"
156150
]
157151
}
158152
],
159153
"source": [
160154
"%%timeit\n",
161-
"str_lookup[long_str_array]"
155+
"int_lookup[int_array]"
162156
]
163157
},
164158
{
165159
"cell_type": "code",
166-
"execution_count": 21,
160+
"execution_count": 6,
167161
"metadata": {},
168162
"outputs": [
169163
{
170164
"name": "stdout",
171165
"output_type": "stream",
172166
"text": [
173-
"105 µs ± 7.44 µs per loop (mean ± std. dev. of 7 runs, 10,000 loops each)\n"
167+
"141 µs ± 30.4 µs per loop (mean ± std. dev. of 7 runs, 10,000 loops each)\n"
174168
]
175169
}
176170
],
177171
"source": [
178172
"%%timeit\n",
179-
"int_lookup[int_array]"
173+
"int_lookup_raw[int_array]"
174+
]
175+
},
176+
{
177+
"cell_type": "markdown",
178+
"metadata": {},
179+
"source": [
180+
"## Length 10 mil"
180181
]
181182
},
182183
{
183184
"cell_type": "code",
184-
"execution_count": 22,
185+
"execution_count": 7,
185186
"metadata": {},
186187
"outputs": [
187188
{
188189
"name": "stdout",
189190
"output_type": "stream",
190191
"text": [
191-
"19.9 ms ± 3.22 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
192+
"872 ms ± 47.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
192193
]
193194
}
194195
],
195196
"source": [
196197
"%%timeit\n",
197-
"int_lookup[long_int_array]"
198+
"str_lookup[long_str_array]"
198199
]
199200
},
200201
{
201202
"cell_type": "code",
202-
"execution_count": 24,
203+
"execution_count": 8,
203204
"metadata": {},
204205
"outputs": [
205206
{
206-
"data": {
207-
"text/plain": [
208-
"83.80952380952382"
209-
]
210-
},
211-
"execution_count": 24,
212-
"metadata": {},
213-
"output_type": "execute_result"
207+
"name": "stdout",
208+
"output_type": "stream",
209+
"text": [
210+
"38.3 ms ± 2.88 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
211+
]
214212
}
215213
],
216214
"source": [
217-
"# how many times slower is the one of size 100_000\n",
218-
"8.8/.105"
215+
"%%timeit\n",
216+
"int_lookup[long_int_array]"
219217
]
220218
},
221219
{
222220
"cell_type": "code",
223-
"execution_count": 28,
221+
"execution_count": 9,
224222
"metadata": {},
225223
"outputs": [
226224
{
227-
"data": {
228-
"text/plain": [
229-
"51.75879396984925"
230-
]
231-
},
232-
"execution_count": 28,
233-
"metadata": {},
234-
"output_type": "execute_result"
225+
"name": "stdout",
226+
"output_type": "stream",
227+
"text": [
228+
"17.4 ms ± 576 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
229+
]
235230
}
236231
],
237232
"source": [
238-
"# how many times slower is the one of size 10_000_000\n",
239-
"1030/19.9"
240-
]
241-
},
242-
{
243-
"cell_type": "code",
244-
"execution_count": 26,
245-
"metadata": {},
246-
"outputs": [],
247-
"source": [
248-
"assert np.all(str_lookup[str_array] == int_lookup[int_array])"
233+
"%%timeit\n",
234+
"int_lookup_raw[long_int_array]"
249235
]
250236
}
251237
],

0 commit comments

Comments
 (0)