News for hackers. Stuff that matters.
Re:Python 3.11 is faster than 3.8 by llimllib on Wednesday October 26, 2022 @12:31PM (#33346092)
I wanted to see what the results for pypy would be.

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...

Re:Python 3.11 is faster than 3.8 by metadat on Wednesday October 26, 2022 @12:44PM (#33346250)
Why is there such a dramatic performance gap / slowdown for 3.10 + 3.11 compared to 3.9.12?
Re:Python 3.11 is faster than 3.8 by qbasic_forever on Wednesday October 26, 2022 @12:45PM (#33346270)
That's pypy 3.9.12, it has a JIT implementation to interpret python. The other two are standard CPython which doesn't JIT interpret the code.
Re:Python 3.11 is faster than 3.8 by metadat on Wednesday October 26, 2022 @01:32PM (#33346840)
Oops, thanks for clarifying.
Re:Python 3.11 is faster than 3.8 by charlieyu1 on Wednesday October 26, 2022 @01:46PM (#33346995)
Does pypy support numpy now?
Re:Python 3.11 is faster than 3.8 by llimllib on Wednesday October 26, 2022 @01:53PM (#33347100)
yes

    $ 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.]]
Re:Python 3.11 is faster than 3.8 by arc-in-space on Wednesday October 26, 2022 @12:45PM (#33346269)
That's 3.9.12 of PyPy, not CPython
Re:Python 3.11 is faster than 3.8 by fordsmith on Wednesday October 26, 2022 @12:47PM (#33346289)
Not OP, but are you taking into consideration that it is not Python 3.9, but pypy, which is distinct
Re:Python 3.11 is faster than 3.8 by masklinn on Wednesday October 26, 2022 @01:10PM (#33346588)
> On my machine (very similar, a macbook pro m1 max):

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.

Re:Python 3.11 is faster than 3.8 by bee_rider on Wednesday October 26, 2022 @01:43PM (#33346958)
It looks very close for 3.11. The measurement from the parent comment includes two other python implementations (not covered in the article).
Re:Python 3.11 is faster than 3.8 by CalebJohn on Wednesday October 26, 2022 @02:17PM (#33347396)
Out of curiosity I ran the same test on a linux laptop with the Ryzen 7 PRO 6850U CPU.

    python 3.10: 60s
    python 3.11: 46s
    pypy 3.9.12:  6s
Looks like pypy performs comparatively better on x86_64
Re:Python 3.11 is faster than 3.8 by llimllib on Wednesday October 26, 2022 @02:29PM (#33347525)
makes sense I guess, it's had a lot more development time I'm sure. Thanks!
Re:Python 3.11 is faster than 3.8 by nerdponx on Wednesday October 26, 2022 @07:06PM (#33350815)
I think PyPy runs under Rosetta on M1, so the overhead is probably from that.
Re:Python 3.11 is faster than 3.8 by llimllib on Wednesday October 26, 2022 @08:43PM (#33351572)
I don't think so; they released ARM support a while ago: https://doc.pypy.org/en/latest/release-2.1.0.html

(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!