random.randrange seem to slow down going from pypy2 to pypy3 - performance bottleneck
I wrote a very simple code to test out how pypy / python and other languages perform with dictionary operations (insertion). PyPy was performing great in version 2. Now I tried version 3 and performance is significantly worse.
Code:
from datetime import datetime
import random
dic = {}
letter = 'qwertyuiopasdfghjklz'
for i in range(5000001):
if i%1000000==0:
now = datetime.now()
print(str(now))
s = ""
for j in range(50):
s += letter[random.randrange(20)]
dic[s] = True
Performance with pypy2 & pypy3:
pypy2 (under 2 seconds):
Python 2.7.18 (8e99af2f9b8e, Apr 02 2022, 14:58:34)
[PyPy 7.3.9 with GCC 11.2.0]
2022-04-30 17:01:52.787058
2022-04-30 17:01:54.112563
2022-04-30 17:01:55.492501
2022-04-30 17:01:56.991456
2022-04-30 17:01:58.374874
2022-04-30 17:01:59.701933
pypy3 (around 5 seconds):
Python 3.8.13 (4b1398fe9d76, Apr 02 2022, 15:38:25)
[PyPy 7.3.9 with GCC 11.2.0]
2022-04-30 17:02:11.642042
2022-04-30 17:02:16.627821
2022-04-30 17:02:21.754386
2022-04-30 17:02:27.061380
2022-04-30 17:02:32.320464
2022-04-30 17:02:37.413582
This was on Linux: Manjaro Linux x86_64, kernel: 5.15.32-1-MANJARO, CPU: AMD Ryzen 5 3600X (12) @ 3.800GHz (but other linuxes it's around the same)
software I use to compare languages: https://github.com/pepe78/python-performance
more details: https://www.frisky.world/2022/04/does-this-mean-pypy-is-going-to-slow.html