#🔒 PyPy Slow M1
68 messages · Page 1 of 1 (latest)
@cyan nymph
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Can you run python3 --version and pypy3 --version?
In general, PyPy is not guaranteed to be faster at everything. It will be worse at some tasks
If you send the code as text I could try running it on my machine, which is not an M1
import time
def test_hash_table(size):
start_time = time.time()
# Hash tablosunu oluştur
table = {}
# Elemanları ekle
for i in range(size):
table[i] = i + 3
end_time = time.time()
print(f"Eklenme süresi ({size} eleman): {end_time - start_time} saniye")
if __name__ == "__main__":
test_hash_table(200000000)
With so many iterations I would expect pypy to run faster. Weird.
what's the result with timeit
Maybe pypy just has a slower hash table implementation
What are your test results? 👀
df@duckpond:/tmp$ pyenv local 3.12.3
df@duckpond:/tmp$ python test.py
Eklenme süresi (20000000 eleman): 2.176011323928833 saniye
df@duckpond:/tmp$ pyenv local pypy3.10-7.3.15
df@duckpond:/tmp$ python test.py
Eklenme süresi (20000000 eleman): 3.1895201206207275 saniye
df@duckpond:/tmp$
I removed one 0 because apparently I don't have enough RAM
!e
import time
def test_hash_table(size):
start_time = time.time()
# Hash tablosunu oluştur
table = {}
# Elemanları ekle
for i in range(size):
table[i] = i + 3
end_time = time.time()
print(f"Eklenme süresi ({size} eleman): {end_time - start_time} saniye")
test_hash_table(200000)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
Eklenme süresi (200000 eleman): 0.049765586853027344 saniye
well... this won't be very useful because we don't have pypy 🤦♂️
Because I'm testing Big O, I use numbers that large. 😅
what about this:
import timeit
def test_hash_table(size):
table = {}
for i in range(size):
table[i] = i + 3
print(timeit.timeit("test_hash_table(1000)", globals=globals()))
% python bench.py # python 3.11
42.39127057400037
% pypy3 bench.py
14.679402190999099
Yeah, pypy might just be ignoring this function when it's called only once
but the improvement would not be just 3 fold
why not?
then it would be more than 10s of times
AFAIK timeit takes care of that aspect while benching
PyPy doesn't speed up all code by 10 times or more, it really depends
but if the func is called only once
👀 Uhh
it should be faster
perfect
see similar result
Try increasingly bigger sizes
get me some RAM
Something like ```py
import timeit
def test_hash_table(size):
table = {}
for i in range(size):
table[i] = i + 3
for size in [1000, 5000, 10_000, 20_000, 50_000, 100_000, 1_000_000, 2_000_000]:
print(size, timeit.timeit(f"test_hash_table({size})", globals=globals(), number=10_000_000 // size))
forgot the fstring in timeit.timeit
fixed
df@duckpond:/tmp$ pyenv local pypy3.10-7.3.15
df@duckpond:/tmp$ python test.py
1000 0.18167751799990128
5000 0.2896245040000167
10000 0.34291394799993213
20000 0.400657911000053
50000 0.5345783589999655
100000 0.5170535390000168
1000000 0.9001765059999798
2000000 0.9751938440000458
df@duckpond:/tmp$ pyenv local 3.12.3
df@duckpond:/tmp$ python test.py
1000 0.4880366159999312
5000 0.6853701789999604
10000 0.7441567559999385
20000 0.774592838999979
50000 0.7592545259999497
100000 0.922786970000061
1000000 1.2632231769999862
2000000 1.3310079849999283
df@duckpond:/tmp$
pypy is faster than cpython
so coming to this
It might only activate the JIT when a function runs a certain number of times
which is why I suggested fiddling with the JIT flags
I'm testing, pypy is faster now. 🤔
What kind of spell did you cast?
could be this
surprising:
CPython
% python bench.py
1000 0.038954724001087015
5000 0.2507603809972352
10000 0.5566556570011016
20000 1.1521581019987934
50000 3.1912593839988403
100000 7.569676145001722
1000000 86.05590453100012
Numba
% python bench.py
1000 8.896027073002188
5000 0.08299110499865492
10000 0.16387912899881485
20000 0.5420342799989157
50000 1.1029537720023654
100000 2.3013623080005345
1000000 31.587898476998816
Pypy
% pypy3 bench.py
1000 0.018211006001365604
5000 0.09754729400083306
10000 0.24521737299801316
20000 0.5805304580026132
50000 1.4802869759987516
100000 3.3758814339998935
1000000 65.33701768899846
numba is way faster than pypy
I did
paste it
you didnt
copy this
but coming back to your code
i dont think that is the way to benchmark
timeit is the way
smth peculiar happens on 1 mil
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.