Runtime Performance Comparison¶
Because SortedContainers is implemented in pure-Python, its performance depends directly on the Python runtime. SortedContainers was primarily developed, tested and benchmarked on CPython 2.7, specifically build:
Python 2.7.11 (default, Mar 1 2016, 18:40:10)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Not all runtimes are created equal. The graphs below compare SortedContainers running on the CPython 2.7, CPython 3.5 and PyPy 5.1 runtimes. The PyPy 5.1 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 2.7 runtime. An implementation performance comparison is also included with data from popular sorted container packages.
SortedContainers 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 load factor performance comparison is also provided.
Though these benchmarks exercise only one API repeatedly, an effort has also been made to simulate real-world workloads. The simulated workload performance comparison contains examples with comparisons to other implementations, load factors, and runtimes.
SortedList¶
Graphs comparing SortedList performance.
SortedDict¶
Graphs comparing SortedDict performance.
__contains__¶
Given a key at random, test whether the key is in the dictionary using SortedDict.__contains__.
