Runtime Performance Comparison¶
Because Sorted Containers is implemented in pure-Python, its performance depends directly on the Python runtime. Sorted Containers is primarily developed, tested and benchmarked on CPython 3.7.
Not all runtimes are created equal. The graphs below compare Sorted Containers 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 implementation performance comparison is also included with data from popular sorted container packages.
Sorted Containers 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.
Sorted List¶
Graphs comparing Sorted List performance.
Sorted Dict¶
Graphs comparing Sorted Dict performance.
__contains__¶
Given a key at random, test whether the key is in the dictionary using
SortedDict.__contains__()
.

Sorted Set¶
Graphs comparing Sorted Set performance.