--

Good question, to which I do not know the answer! However, Python 3.11 included a lot of optimizations intended to make things faster. Speed has become a focus of Python and they are planning each odd-numbered revision to have speed improvements.

That said, on my machine I find this difference on each Python version!

Here are the results. Note the significant regression on Python 3.12; Python 3.13 is still beta and further improvements are expected.

$ python3.13 comp.py
0.3722045000176877
0.40474120806902647

$ python3.12 comp.py
0.34572983300313354
0.3946095840074122

$ python3.11 comp.py
0.29654345801100135
0.33629066590219736

$ python3.10 comp.py
0.34012566693127155
0.49331537494435906

$ python3.9 comp.py
0.37815795799999996
0.542671125

$ python3.8 comp.py
0.36949625
0.535385208

$ python3.7 comp.py
0.7370107079999999
0.965682

$ python3.6 comp.py
0.6712762909010053
0.9620650410652161

--

--