Code Snippets

Python 3.11 thirty percent faster indeed

Two weeks back the new version 3.11 of Python was released with the promise of a significant speedup. Let’s test it!

For fun, I’m maintaining a small benchmarking project. There, a couple of computational tasks are solved with Python and with different speedup methods such as Cython, Numba and C extensions written in C++ or Rust. Main purpose for me was to figure out which method has the greatest effect and how good the user experience is.

Now that Python 3.11 is officially released with the note that a speedup of 10-60% was reached thanks to the Faster CPython project, it was time to check what it does to my benchmarks.

So I quickly updated my Python environment and rerun the benchmark suite. These are the results that I got:

So, I can confirm some 8-37% speedup without changing a single line of code. This still doesn’t make Python the new high performance language. But it is a lot, given that it comes for free with the CPython interpreter. Similar improvements couldn’t be seen with the update to 3.10, but the original plan for the faster CPython project still gives hope for more in the next versions. Thanks to Guido van Rossum, Mark Shannon and all the helping hands who drive the project!

For reference below the complete results with Python 3.11. The 3.10 results and the code can be found in the Github repository.

System information:

Architecture: x86_64 / 64bit
System: Linux / 5.15.11-arch2-1
Python: CPython 3.9.9 built with ('glibc', '2.33')
Processors: 
    16 x  AMD Ryzen 7 5700U with Radeon Graphics
    
mergesort
	  106ms - Python 3.10
	   67ms - Python 3.11
	  144ms - Numba
	   35ms - Cython
	    7ms - C++ (cython)
	    8ms - C++ (pybind11)
	    6ms - Rust
groupby_sum
	   86ms - Python 3.10
	   71ms - Python 3.11
	   69ms - Cython
	   58ms - Rust
string_slice
	   10ms - Python 3.10
	    7ms - Python 3.11
	    7ms - Cython
	   31ms - C++ (pybind11)
	   22ms - Rust
ngram_count
	  459ms - Python 3.10
	  421ms - Python 3.11
	  386ms - Numba
	  237ms - Cython
	  280ms - C++ (pybind11)
	  288ms - Rust
ngram_count_parallel
	  254ms - Python 3.10
	  202ms - Python 3.11
	  200ms - Rust
minhash
	  566ms - Python 3.10
	  498ms - Python 3.11
	  508ms - Cython
	  130ms - C++ (pybind11)
	  109ms - Rust

This blog is written and maintained by Christian Krudewig