Because :doc:`SortedContainers<index>` is implemented in pure-Python, its performance depends directly on the Python runtime. :doc:`SortedContainers<index>` 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 :doc:`SortedContainers<index>` 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 :doc:`implementation performance comparison<performance>` is also included with data from popular sorted container packages.
:doc:`SortedContainers<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.
Graphs comparing :doc:`SortedList<sortedlist>` performance.
Initializing with a list of random numbers.
Randomly adding values using :ref:`SortedList.add<SortedList.add>`.
Randomly testing membership using :ref:`SortedList.__contains__<SortedList.__contains__>`.
Counting objects at random using :ref:`SortedList.count<SortedList.count>`.
Deleting objects at random using :ref:`SortedList.__delitem__<SortedList.__delitem__>`.
Retrieving ojbects by index using :ref:`SortedList.__getitem__<SortedList.__getitem__>`.
Finding the index of an object using :ref:`SortedList.index<SortedList.index>`.
Iterating a SortedList using :ref:`SortedList.__iter__<SortedList.__iter__>`.
Removing the last object using :ref:`SortedList.pop<SortedList.pop>`.
Remove an object at random using :ref:`SortedList.remove<SortedList.remove>`.
Updating a SortedList with a large iterable using :ref:`SortedList.update<SortedList.update>`.
Updating a SortedList with a small iterable using :ref:`SortedList.update<SortedList.update>`.
Graphs comparing :doc:`SortedDict<sorteddict>` performance.
Initializing with a list of pairs of random numbers.
Given a key at random, test whether the key is in the dictionary using :ref:`SortedDict.__contains__<SortedDict.__contains__>`.
Given a key at random, retrieve the value using :ref:`SortedDict.__getitem__<SortedDict.__getitem__>`.
Given a key at random, set the value using :ref:`SortedDict.__setitem__<SortedDict.__setitem__>`.
Given a key at random, delete the value using :ref:`SortedDict.__delitem__<SortedDict.__delitem__>`.
Iterate the keys of a SortedDict using :ref:`SortedDict.__iter__<SortedDict.__iter__>`.
Given an existing key at random, set the value using :ref:`SortedDict.__setitem__<SortedDict.__setitem__>`.
Graphs comparing :doc:`SortedSet<sortedset>` performance.
Initializing with a list of random numbers.
Randomly add values using :ref:`SortedSet.add<SortedSet.add>`.
Randomly test membership using :ref:`SortedSet.__contains__<SortedSet.__contains__>`.
Set difference using :ref:`SortedSet.difference<SortedSet.difference>`.
Set difference using :ref:`SortedSet.difference<SortedSet.difference>`.
Set difference using :ref:`SortedSet.difference<SortedSet.difference>`.
Set difference using :ref:`SortedSet.difference<SortedSet.difference>`.
Set difference using :ref:`SortedSet.difference_update<SortedSet.difference_update>`.
Set difference using :ref:`SortedSet.difference_update<SortedSet.difference_update>`.
Set difference using :ref:`SortedSet.difference_update<SortedSet.difference_update>`.
Set difference using :ref:`SortedSet.difference_update<SortedSet.difference_update>`.
Set intersection using :ref:`SortedSet.intersection<SortedSet.intersection>`.
Set intersection using :ref:`SortedSet.intersection<SortedSet.intersection>`.
Set intersection using :ref:`SortedSet.intersection<SortedSet.intersection>`.
Set intersection using :ref:`SortedSet.intersection<SortedSet.intersection>`.
Set intersection using :ref:`SortedSet.intersection_update<SortedSet.intersection_update>`.
Set intersection using :ref:`SortedSet.intersection_update<SortedSet.intersection_update>`.
Set intersection using :ref:`SortedSet.intersection_update<SortedSet.intersection_update>`.
Set intersection using :ref:`SortedSet.intersection_update<SortedSet.intersection_update>`.
Iterating a set using :ref:`iter(SortedSet)<SortedSet.__iter__>`.
Remove the last item in a set using :ref:`SortedSet.pop<SortedSet.pop>`.
Remove an item at random using :ref:`SortedSet.remove<SortedSet.remove>`.
Set union using :ref:`SortedSet.union<SortedSet.union>`.
Set union using :ref:`SortedSet.union<SortedSet.union>`.
Set union using :ref:`SortedSet.union<SortedSet.union>`.
Set union using :ref:`SortedSet.union<SortedSet.union>`.
Set update using :ref:`SortedSet.update<SortedSet.update>`.
Set update using :ref:`SortedSet.update<SortedSet.update>`.
Set update using :ref:`SortedSet.update<SortedSet.update>`.
Set update using :ref:`SortedSet.update<SortedSet.update>`.
Set symmetric-difference using :ref:`SortedSet.symmetric_difference<SortedSet.symmetric_difference>`.
Set symmetric-difference using :ref:`SortedSet.symmetric_difference<SortedSet.symmetric_difference>`.
Set symmetric-difference using :ref:`SortedSet.symmetric_difference<SortedSet.symmetric_difference>`.
Set symmetric-difference using :ref:`SortedSet.symmetric_difference<SortedSet.symmetric_difference>`.
Set symmetric-difference using :ref:`SortedSet.symmetric_difference_update<SortedSet.symmetric_difference_update>`.
Set symmetric-difference using :ref:`SortedSet.symmetric_difference_update<SortedSet.symmetric_difference_update>`.
Set symmetric-difference using :ref:`SortedSet.symmetric_difference_update<SortedSet.symmetric_difference_update>`.
Set symmetric-difference using :ref:`SortedSet.symmetric_difference_update<SortedSet.symmetric_difference_update>`.
























































