Debian Codegraph @

docs/performance-runtime.rst

raw
1 Runtime Performance Comparison
2 ==============================
3
4 Because :doc:`Sorted Containers<index>` is implemented in pure-Python, its
5 performance depends directly on the Python runtime. :doc:`Sorted
6 Containers<index>` is primarily developed, tested and benchmarked on CPython
7 3.7.
8
9 Not all runtimes are created equal. The graphs below compare :doc:`Sorted
10 Containers<index>` running on the CPython 3.7, CPython 2.7, and PyPy
11 runtimes. As of Python 3.7 the CPython 3.7 runtime is now faster than the
12 CPython 2.7 runtime. The PyPy runtime displays much more variability due to its
13 JIT-ed nature. Once the just-in-time compiler optimizes the code, performance
14 is often two to ten times faster.
15
16 Performance of competing implementations are benchmarked against the CPython
17 3.7 runtime. An :doc:`implementation performance comparison<performance>` is
18 also included with data from popular sorted container packages.
19
20 :doc:`Sorted Containers<index>` uses a segmented-list data structure similar to
21 a B-tree limited to two levels of nodes. As part of the implementation, a load
22 factor is used to determine how many values should be stored in each node. This
23 can have a significant impact on performance and a :doc:`load factor
24 performance comparison<performance-load>` is also provided.
25
26 Though these benchmarks exercise only one API repeatedly, an effort has also
27 been made to simulate real-world workloads. The :doc:`simulated workload
28 performance comparison<performance-workload>` contains examples with
29 comparisons to other implementations, load factors, and runtimes.
30
31 .. currentmodule:: sortedcontainers
32
33 Sorted List
34 -----------
35
36 Graphs comparing :doc:`sortedlist` performance.
37
38 __init__
39 ........
40
41 Initializing with a list of random numbers using :func:`SortedList.__init__`.
42
43 .. image:: _static/SortedList_runtime-init.png
44
45 add
46 ...
47
48 Randomly adding values using :func:`SortedList.add`.
49
50 .. image:: _static/SortedList_runtime-add.png
51
52 contains
53 ........
54
55 Randomly testing membership using :func:`SortedList.__contains__`.
56
57 .. image:: _static/SortedList_runtime-contains.png
58
59 count
60 .....
61
62 Counting objects at random using :func:`SortedList.count`.
63
64 .. image:: _static/SortedList_runtime-count.png
65
66 __delitem__
67 ...........
68
69 Deleting objects at random using :func:`SortedList.__delitem__`.
70
71 .. image:: _static/SortedList_runtime-delitem.png
72
73 __getitem__
74 ...........
75
76 Retrieving objects by index using :func:`SortedList.__getitem__`.
77
78 .. image:: _static/SortedList_runtime-getitem.png
79
80 index
81 .....
82
83 Finding the index of an object using :func:`SortedList.index`.
84
85 .. image:: _static/SortedList_runtime-index.png
86
87 iter
88 ....
89
90 Iterating a SortedList using :func:`SortedList.__iter__`.
91
92 .. image:: _static/SortedList_runtime-iter.png
93
94 pop
95 ...
96
97 Removing the last object using :func:`SortedList.pop`.
98
99 .. image:: _static/SortedList_runtime-pop.png
100
101 remove
102 ......
103
104 Remove an object at random using :func:`SortedList.remove`.
105
106 .. image:: _static/SortedList_runtime-remove.png
107
108 update_large
109 ............
110
111 Updating a SortedList with a large iterable using :func:`SortedList.update`.
112
113 .. image:: _static/SortedList_runtime-update_large.png
114
115 update_small
116 ............
117
118 Updating a SortedList with a small iterable using :func:`SortedList.update`.
119
120 .. image:: _static/SortedList_runtime-update_small.png
121
122 Sorted Dict
123 -----------
124
125 Graphs comparing :doc:`sorteddict` performance.
126
127 __init__
128 ........
129
130 Initializing with a list of pairs of random numbers using
131 :func:`SortedDict.__init__`.
132
133 .. image:: _static/SortedDict_runtime-init.png
134
135 __contains__
136 ............
137
138 Given a key at random, test whether the key is in the dictionary using
139 :func:`SortedDict.__contains__`.
140
141 .. image:: _static/SortedDict_runtime-contains.png
142
143 __getitem__
144 ...........
145
146 Given a key at random, retrieve the value using :func:`SortedDict.__getitem__`.
147
148 .. image:: _static/SortedDict_runtime-getitem.png
149
150 __setitem__
151 ...........
152
153 Given a key at random, set the value using :func:`SortedDict.__setitem__`.
154
155 .. image:: _static/SortedDict_runtime-setitem.png
156
157 __delitem__
158 ...........
159
160 Given a key at random, delete the value using :func:`SortedDict.__delitem__`.
161
162 .. image:: _static/SortedDict_runtime-delitem.png
163
164 iter
165 ....
166
167 Iterate the keys of a SortedDict using :func:`SortedDict.__iter__`.
168
169 .. image:: _static/SortedDict_runtime-iter.png
170
171 setitem_existing
172 ................
173
174 Given an existing key at random, set the value using
175 :func:`SortedDict.__setitem__`.
176
177 .. image:: _static/SortedDict_runtime-setitem_existing.png
178
179 Sorted Set
180 ----------
181
182 Graphs comparing :doc:`sortedset` performance.
183
184 __init__
185 ........
186
187 Initializing with a list of random numbers using :func:`SortedSet.__init__`.
188
189 .. image:: _static/SortedSet_runtime-init.png
190
191 add
192 ...
193
194 Randomly add values using :func:`SortedSet.add`.
195
196 .. image:: _static/SortedSet_runtime-add.png
197
198 contains
199 ........
200
201 Randomly test membership using :func:`SortedSet.__contains__`.
202
203 .. image:: _static/SortedSet_runtime-contains.png
204
205 difference_large
206 ................
207
208 Set difference using :func:`SortedSet.difference`.
209
210 .. image:: _static/SortedSet_runtime-difference_large.png
211
212 difference_medium
213 .................
214
215 Set difference using :func:`SortedSet.difference`.
216
217 .. image:: _static/SortedSet_runtime-difference_medium.png
218
219 difference_small
220 ................
221
222 Set difference using :func:`SortedSet.difference`.
223
224 .. image:: _static/SortedSet_runtime-difference_small.png
225
226 difference_tiny
227 ...............
228
229 Set difference using :func:`SortedSet.difference`.
230
231 .. image:: _static/SortedSet_runtime-difference_tiny.png
232
233 difference_update_large
234 .......................
235
236 Set difference using :func:`SortedSet.difference_update`.
237
238 .. image:: _static/SortedSet_runtime-difference_update_large.png
239
240 difference_update_medium
241 ........................
242
243 Set difference using :func:`SortedSet.difference_update`.
244
245 .. image:: _static/SortedSet_runtime-difference_update_medium.png
246
247 difference_update_small
248 .......................
249
250 Set difference using :func:`SortedSet.difference_update`.
251
252 .. image:: _static/SortedSet_runtime-difference_update_small.png
253
254 difference_update_tiny
255 ......................
256
257 Set difference using :func:`SortedSet.difference_update`.
258
259 .. image:: _static/SortedSet_runtime-difference_update_tiny.png
260
261 intersection_large
262 ..................
263
264 Set intersection using :func:`SortedSet.intersection`.
265
266 .. image:: _static/SortedSet_runtime-intersection_large.png
267
268 intersection_medium
269 ...................
270
271 Set intersection using :func:`SortedSet.intersection`.
272
273 .. image:: _static/SortedSet_runtime-intersection_medium.png
274
275 intersection_small
276 ..................
277
278 Set intersection using :func:`SortedSet.intersection`.
279
280 .. image:: _static/SortedSet_runtime-intersection_small.png
281
282 intersection_tiny
283 .................
284
285 Set intersection using :func:`SortedSet.intersection`.
286
287 .. image:: _static/SortedSet_runtime-intersection_tiny.png
288
289 intersection_update_large
290 .........................
291
292 Set intersection using :func:`SortedSet.intersection_update`.
293
294 .. image:: _static/SortedSet_runtime-intersection_update_large.png
295
296 intersection_update_medium
297 ..........................
298
299 Set intersection using :func:`SortedSet.intersection_update`.
300
301 .. image:: _static/SortedSet_runtime-intersection_update_medium.png
302
303 intersection_update_small
304 .........................
305
306 Set intersection using :func:`SortedSet.intersection_update`.
307
308 .. image:: _static/SortedSet_runtime-intersection_update_small.png
309
310 intersection_update_tiny
311 ........................
312
313 Set intersection using :func:`SortedSet.intersection_update`.
314
315 .. image:: _static/SortedSet_runtime-intersection_update_tiny.png
316
317 iter
318 ....
319
320 Iterating a set using :func:`iter(SortedSet)`.
321
322 .. image:: _static/SortedSet_runtime-iter.png
323
324 pop
325 ...
326
327 Remove the last item in a set using :func:`SortedSet.pop`.
328
329 .. image:: _static/SortedSet_runtime-pop.png
330
331 remove
332 ......
333
334 Remove an item at random using :func:`SortedSet.remove`.
335
336 .. image:: _static/SortedSet_runtime-remove.png
337
338 union_large
339 ...........
340
341 Set union using :func:`SortedSet.union`.
342
343 .. image:: _static/SortedSet_runtime-union_large.png
344
345 union_medium
346 ............
347
348 Set union using :func:`SortedSet.union`.
349
350 .. image:: _static/SortedSet_runtime-union_medium.png
351
352 union_small
353 ...........
354
355 Set union using :func:`SortedSet.union`.
356
357 .. image:: _static/SortedSet_runtime-union_small.png
358
359 union_tiny
360 ..........
361
362 Set union using :func:`SortedSet.union`.
363
364 .. image:: _static/SortedSet_runtime-union_tiny.png
365
366 update_large
367 ............
368
369 Set update using :func:`SortedSet.update`.
370
371 .. image:: _static/SortedSet_runtime-update_large.png
372
373 update_medium
374 .............
375
376 Set update using :func:`SortedSet.update`.
377
378 .. image:: _static/SortedSet_runtime-update_medium.png
379
380 update_small
381 ............
382
383 Set update using :func:`SortedSet.update`.
384
385 .. image:: _static/SortedSet_runtime-update_small.png
386
387 update_tiny
388 ...........
389
390 Set update using :func:`SortedSet.update`.
391
392 .. image:: _static/SortedSet_runtime-update_tiny.png
393
394 symmetric_difference_large
395 ..........................
396
397 Set symmetric-difference using :func:`SortedSet.symmetric_difference`.
398
399 .. image:: _static/SortedSet_runtime-symmetric_difference_large.png
400
401 symmetric_difference_medium
402 ...........................
403
404 Set symmetric-difference using :func:`SortedSet.symmetric_difference`.
405
406 .. image:: _static/SortedSet_runtime-symmetric_difference_medium.png
407
408 symmetric_difference_small
409 ..........................
410
411 Set symmetric-difference using :func:`SortedSet.symmetric_difference`.
412
413 .. image:: _static/SortedSet_runtime-symmetric_difference_small.png
414
415 symmetric_difference_tiny
416 .........................
417
418 Set symmetric-difference using :func:`SortedSet.symmetric_difference`.
419
420 .. image:: _static/SortedSet_runtime-symmetric_difference_tiny.png
421
422 symm_diff_update_large
423 ......................
424
425 Set symmetric-difference using :func:`SortedSet.symmetric_difference_update`.
426
427 .. image:: _static/SortedSet_runtime-symmetric_difference_update_large.png
428
429 symm_diff_update_medium
430 .......................
431
432 Set symmetric-difference using :func:`SortedSet.symmetric_difference_update`.
433
434 .. image:: _static/SortedSet_runtime-symmetric_difference_update_medium.png
435
436 symm_diff_update_small
437 ......................
438
439 Set symmetric-difference using :func:`SortedSet.symmetric_difference_update`.
440
441 .. image:: _static/SortedSet_runtime-symmetric_difference_update_small.png
442
443 symm_diff_update_tiny
444 .....................
445
446 Set symmetric-difference using :func:`SortedSet.symmetric_difference_update`.
447
448 .. image:: _static/SortedSet_runtime-symmetric_difference_update_tiny.png