Roland's homepage

My random knot in the Web

Python 3.11 speed comparison with 3.9

Since Python 3.11.0 came out recently, I wanted to compare its speed with 3.9.15 on some of my own “benchmark” programs.

Both versions are in the default configuration as built by the FreeBSD ports system.

TL;DR Python 3.11 yielded speed improvements in the order of 25% in my tests.

To measure only the behavior of Python code, the programs under test do not use extension modules like numpy, pandas or others.

ent_without_numpy

This is part of my Python port of John Walker’s ent program. More specifically (as the name inplies) this is written in pure python without using numpy.

First, python 3.9.15:

> /usr/bin/time python3.9 ent_without_numpy.py test/random.dat
- Entropy is 7.999982 bits per byte.
- Optimum compression would reduce the size
of this 10485760 byte file by 0%.
- χ² distribution for 10485760 samples is 259.03, and randomly
would exceed this value 41.80% of the times.
According to the χ² test, this sequence looks random.
- Arithmetic mean value of data bytes is 127.5116 (random = 127.5).
- Monte Carlo value for π is 3.139875958 (error 0.05%).
- Serial correlation coefficient is -0.000296 (totally uncorrelated = 0.0).
        3.37 real         3.27 user         0.09 sys

Then python 3.11.0:

- Entropy is 7.999982 bits per byte.
- Optimum compression would reduce the size
of this 10485760 byte file by 0%.
- χ² distribution for 10485760 samples is 259.03, and randomly
would exceed this value 41.80% of the times.
According to the χ² test, this sequence looks random.
- Arithmetic mean value of data bytes is 127.5116 (random = 127.5).
- Monte Carlo value for π is 3.139875958 (error 0.05%).
- Serial correlation coefficient is -0.000296 (totally uncorrelated = 0.0).
        2.46 real         2.40 user         0.06 sys

That is a pretty significant (1 - 2.46 / 3.37) = 27% improvement. Note that both Python versions produce identical output.

stl2pov

This is part of my stltools set:

> /usr/bin/time python3.9 stl2pov.py ../testdata-stltools/headrest_mesh.stl
        1.71 real         1.43 user         0.14 sys

> /usr/bin/time python3.11 stl2pov.py ../testdata-stltools/headrest_mesh.stl
        1.34 real         1.19 user         0.15 sys

The improvement here is (1 - 1.34 / 1.71) = 21.6%. Apart from a comment containing the date and time the file was generated, the resulting files were identical.

Conclusion

Python 3.11 brings real and significant improvements in speed.


For comments, please send me an e-mail.


Related articles


←  Getting the first or last item from a dictview without a list On Python speed  →