|
2 | 2 | "cells": [ |
3 | 3 | { |
4 | 4 | "cell_type": "code", |
5 | | - "execution_count": 15, |
| 5 | + "execution_count": 1, |
6 | 6 | "metadata": {}, |
7 | 7 | "outputs": [], |
8 | 8 | "source": [ |
|
14 | 14 | }, |
15 | 15 | { |
16 | 16 | "cell_type": "code", |
17 | | - "execution_count": 16, |
| 17 | + "execution_count": 2, |
18 | 18 | "metadata": {}, |
19 | 19 | "outputs": [ |
20 | 20 | { |
|
73 | 73 | "2 2 C 0.9" |
74 | 74 | ] |
75 | 75 | }, |
76 | | - "execution_count": 16, |
| 76 | + "execution_count": 2, |
77 | 77 | "metadata": {}, |
78 | 78 | "output_type": "execute_result" |
79 | 79 | } |
|
85 | 85 | " 'value|float': [0.3, 0.5, 0.9]\n", |
86 | 86 | " }\n", |
87 | 87 | ")\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", |
88 | 94 | "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", |
90 | 97 | "df2_index = df2.reset_index()\n", |
91 | 98 | "df2_index" |
92 | 99 | ] |
93 | 100 | }, |
94 | 101 | { |
95 | 102 | "cell_type": "code", |
96 | | - "execution_count": 17, |
| 103 | + "execution_count": 3, |
97 | 104 | "metadata": {}, |
98 | 105 | "outputs": [], |
99 | 106 | "source": [ |
|
106 | 113 | ] |
107 | 114 | }, |
108 | 115 | { |
109 | | - "cell_type": "code", |
110 | | - "execution_count": 18, |
| 116 | + "cell_type": "markdown", |
111 | 117 | "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 | | - ], |
124 | 118 | "source": [ |
125 | | - "np.tile(np.array([1,2]), 2)" |
| 119 | + "## length 100k" |
126 | 120 | ] |
127 | 121 | }, |
128 | 122 | { |
129 | 123 | "cell_type": "code", |
130 | | - "execution_count": 19, |
| 124 | + "execution_count": 4, |
131 | 125 | "metadata": {}, |
132 | 126 | "outputs": [ |
133 | 127 | { |
134 | 128 | "name": "stdout", |
135 | 129 | "output_type": "stream", |
136 | 130 | "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" |
138 | 132 | ] |
139 | 133 | } |
140 | 134 | ], |
|
145 | 139 | }, |
146 | 140 | { |
147 | 141 | "cell_type": "code", |
148 | | - "execution_count": 20, |
| 142 | + "execution_count": 5, |
149 | 143 | "metadata": {}, |
150 | 144 | "outputs": [ |
151 | 145 | { |
152 | 146 | "name": "stdout", |
153 | 147 | "output_type": "stream", |
154 | 148 | "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" |
156 | 150 | ] |
157 | 151 | } |
158 | 152 | ], |
159 | 153 | "source": [ |
160 | 154 | "%%timeit\n", |
161 | | - "str_lookup[long_str_array]" |
| 155 | + "int_lookup[int_array]" |
162 | 156 | ] |
163 | 157 | }, |
164 | 158 | { |
165 | 159 | "cell_type": "code", |
166 | | - "execution_count": 21, |
| 160 | + "execution_count": 6, |
167 | 161 | "metadata": {}, |
168 | 162 | "outputs": [ |
169 | 163 | { |
170 | 164 | "name": "stdout", |
171 | 165 | "output_type": "stream", |
172 | 166 | "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" |
174 | 168 | ] |
175 | 169 | } |
176 | 170 | ], |
177 | 171 | "source": [ |
178 | 172 | "%%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" |
180 | 181 | ] |
181 | 182 | }, |
182 | 183 | { |
183 | 184 | "cell_type": "code", |
184 | | - "execution_count": 22, |
| 185 | + "execution_count": 7, |
185 | 186 | "metadata": {}, |
186 | 187 | "outputs": [ |
187 | 188 | { |
188 | 189 | "name": "stdout", |
189 | 190 | "output_type": "stream", |
190 | 191 | "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" |
192 | 193 | ] |
193 | 194 | } |
194 | 195 | ], |
195 | 196 | "source": [ |
196 | 197 | "%%timeit\n", |
197 | | - "int_lookup[long_int_array]" |
| 198 | + "str_lookup[long_str_array]" |
198 | 199 | ] |
199 | 200 | }, |
200 | 201 | { |
201 | 202 | "cell_type": "code", |
202 | | - "execution_count": 24, |
| 203 | + "execution_count": 8, |
203 | 204 | "metadata": {}, |
204 | 205 | "outputs": [ |
205 | 206 | { |
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 | + ] |
214 | 212 | } |
215 | 213 | ], |
216 | 214 | "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]" |
219 | 217 | ] |
220 | 218 | }, |
221 | 219 | { |
222 | 220 | "cell_type": "code", |
223 | | - "execution_count": 28, |
| 221 | + "execution_count": 9, |
224 | 222 | "metadata": {}, |
225 | 223 | "outputs": [ |
226 | 224 | { |
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 | + ] |
235 | 230 | } |
236 | 231 | ], |
237 | 232 | "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]" |
249 | 235 | ] |
250 | 236 | } |
251 | 237 | ], |
|
0 commit comments