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