by llimllib · 4y ago · 0 comments
On my machine (very similar, a macbook pro m1 max):
python 3.10: 52s
python 3.11: 35s
pypy 3.9.12: 10s
(This test is basically a perfect test for JITs: one loop repeated many times)https://gist.github.com/llimllib/7af8144a92d3c2e1fc58be62988...
python 3.10: 60s
python 3.11: 46s
pypy 3.9.12: 6s
Looks like pypy performs comparatively better on x86_64(I could be wrong)
edit: oh, huh I think you're right that it's running here on rosetta:
$ file installs/python/pypy3.9-7.3.9/bin/pypy
installs/python/pypy3.9-7.3.9/bin/pypy: Mach-O 64-bit executable x86_64
Wonder if there's a way to run a native version?edit 2: there are nightlies here: https://buildbot.pypy.org/nightly/py3.9/
Running the latest, a native binary gives more than 2x speedup:
# first you have to allow all the unsigned binaries to run
$ xattr -dr com.apple.quarantine pypy-c-jit-106295-5dd3b18303e2-macos_arm64/bin/*
# then we get 3.5s:
$ time pypy-c-jit-106295-5dd3b18303e2-macos_arm64/bin/pypy nbody.py 10000000
-0.169075164
-0.169077842
real 0m3.522s
user 0m3.468s
sys 0m0.045s
pypy continues to impress! $ pip install numpy
<snip building wheel>
$ python --version && python -c "import numpy; print(numpy.identity(5))"
Python 3.9.12 (05fbe3aa5b0845e6c37239768aa455451aa5faba, Mar 29 2022, 09:54:47)
[PyPy 7.3.9 with GCC Apple LLVM 13.0.0 (clang-1300.0.29.30)]
[[1. 0. 0. 0. 0.]
[0. 1. 0. 0. 0.]
[0. 0. 1. 0. 0.]
[0. 0. 0. 1. 0.]
[0. 0. 0. 0. 1.]]Should make essentially no difference then, since I rather doubt the Python implementation of n-body can leverage the GPU, or strains the RAM so much that the 200GB/s of the Pro (IIRC) would be an issue.