Python 3.12, 3.11, 3.10, 3.9, 3.8 performance vs 2.7

Created:22-06-04 14:18    Updated:23-10-13 22:20


About a decade ago, I developed a pure Python ODBC module (pypyodbc), and I was very curious about how compatible this module was on different implementations of Python, including: CPython 2.X, CPython 3.X, PyPy and even IronPython.

While the pure Python module could run normally on all of the above-mentioned interpreters, I was interested in using it to test the performance of those Python implementations. Below are the results:

Version Python 3.12b1 PyPy Python 3.11 Nuitka + Python 3.7 Python 3.10 Python 3.9 Python 3.8 Python 2.7 Python 3.7 IronPython
Total time 41.5 42.5 43.5 43.6 46.3 48.8 49.8 52.4 73.0 188.8


Summary

Python 3.12 Beta1 > PyPy > Python 3.11 Nuitka + Python 3.7 > CPython 3.10 > CPython 3.9 CPython 3.8 > CPython 2.7 > CPython 3.7 > IronPython

  • Python 3.12 Beta1 seems to be the fastest, and the first CPython version to outperform PyPy in my test.

  • CPython is faster version by version. But this wasn't true until Python 3.8 as Python 3.X outperformed Python 2.7.

  • PyPy is always speeding up seconds by seconds when running the script. So, actually, if the script ends quickly, it doesn't give PyPy a chance to catch up.

  • If code is compiled by Nuitka it can run faster! This is great news for those who want to release programs as executables instead of source codes. The compiled code can run on PCs without Python installed, and it also protects your code if you don't want others to get your source code. Moreover, it runs even faster than the baseline Python!

  • IronPython was about three times slower than Python 2.7 in my case, with a quite noticeable (unbearable) cold startup time.

Considering that for compatibility purposes, the testing script and the module itself were written in a way that both 2.X and 3.X could run, but more friendly to Python 2.7, the performance of 3.x interpreter should be even better if codes are written in native 3.x syntax.

- End -

See also:

CherryPy performance on Python 2.7 / 3.9 / 3.10, analyzed by Locust load testing!


An Online Pomodoro Timer is here