Re: Help me understand why PyPy is so slow in my benchmark

CF Bolz-Tereick via pypy-dev <[email protected]> Wed, 18 Sep 2024 23:04:55 +0200
Newsgroups gmane.comp.python.pypy
Message-ID <[email protected]>
--===============4882256886515716948==
Content-Type: multipart/alternative;
 boundary=----N3EJ7YSVNCRNXE67Y9FO567AT5J4FZ
Content-Transfer-Encoding: 7bit

------N3EJ7YSVNCRNXE67Y9FO567AT5J4FZ
Content-Type: text/plain;
 charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi Jeremy,

Can you share how you are running this function? I tried a few variants, a=
nd pypy is often faster than CPython on my attempts, so the rest of your co=
de is necessary to find out what's wrong=2E

Cheers,

CF=20

On September 18, 2024 5:43:06 AM GMT+02:00, Jeremy Brown <mischif@mischivo=
us=2Ecom> wrote:
>Hello,
>
>I'm working on a project that involves benchmarking CPython and PyPy
>across a few benchmarks I've devised, but PyPy is so much slower than
>CPython I feel I must have made some sort of mistake=2E One major
>headscratcher is that CPython runtimes hold stable while PyPy appears
>to get worse as the benchmark progresses=2E
>
>I've included an excerpt of the benchmark below that shows the issue,
>if I can attach files that won't be lost I can attach a full copy; I
>don't believe the string operations are the issue because the
>micro-tuning tips suggest the JIT reduces concatenation overhead in
>scenarios like these (if I'm reading the page right)=2E [1]
>
>def recurse(num):
>    if num >=3D 1000:
>        return "M" + recurse(num - 1000)
>
>    elif num >=3D 900:
>        return "CM" + recurse(num - 900)
>
>    elif num >=3D 500:
>        return "D" + recurse(num - 500)
>
>    elif num >=3D 400:
>        return "CD" + recurse(num - 400)
>
>    elif num >=3D 100:
>        return "C" + recurse(num - 100)
>
>    elif num >=3D 90:
>        return "XC" + recurse(num - 90)
>
>    elif num >=3D 50:
>        return "L" + recurse(num - 50)
>
>    elif num >=3D 40:
>        return "XL" + recurse(num - 40)
>
>    elif num >=3D 10:
>        return "X" + recurse(num - 10)
>
>    elif num >=3D 9:
>        return "IX" + recurse(num - 9)
>
>    elif num >=3D 5:
>        return "V" + recurse(num - 5)
>
>    elif num >=3D 4:
>        return "IV" + recurse(num - 4)
>
>    elif num >=3D 1:
>        return "I" + recurse(num - 1)
>
>    else:
>        return ""
>
>-Jeremy
>
>[1]: https://pypy=2Eorg/performance=2Ehtml#micro-tuning-tips
>_______________________________________________
>pypy-dev mailing list -- pypy-dev@python=2Eorg
>To unsubscribe send an email to pypy-dev-leave@python=2Eorg
>https://mail=2Epython=2Eorg/mailman3/lists/pypy-dev=2Epython=2Eorg/
>Member address: cfbolz@gmx=2Ede

------N3EJ7YSVNCRNXE67Y9FO567AT5J4FZ
Content-Type: text/html;
 charset=utf-8
Content-Transfer-Encoding: quoted-printable

<html><head></head><body><div dir=3D"auto">Hi Jeremy,<br><br>Can you share =
how you are running this function? I tried a few variants, and pypy is ofte=
n faster than CPython on my attempts, so the rest of your code is necessary=
 to find out what's wrong=2E<br><br>Cheers,<br><br>CF </div><br><br><div cl=
ass=3D"gmail_quote"><div dir=3D"auto">On September 18, 2024 5:43:06 AM GMT+=
02:00, Jeremy Brown &lt;mischif@mischivous=2Ecom&gt; wrote:</div><blockquot=
e class=3D"gmail_quote" style=3D"margin: 0pt 0pt 0pt 0=2E8ex; border-left: =
1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class=3D"k9mail"><div dir=3D"auto">Hello,<br><br>I'm working on a pro=
ject that involves benchmarking CPython and PyPy<br>across a few benchmarks=
 I've devised, but PyPy is so much slower than<br>CPython I feel I must hav=
e made some sort of mistake=2E One major<br>headscratcher is that CPython r=
untimes hold stable while PyPy appears<br>to get worse as the benchmark pro=
gresses=2E<br><br>I've included an excerpt of the benchmark below that show=
s the issue,<br>if I can attach files that won't be lost I can attach a ful=
l copy; I<br>don't believe the string operations are the issue because the<=
br>micro-tuning tips suggest the JIT reduces concatenation overhead in<br>s=
cenarios like these (if I'm reading the page right)=2E [1]<br><br>def recur=
se(num):<br>    if num &gt;=3D 1000:<br>        return "M" + recurse(num - =
1000)<br><br>    elif num &gt;=3D 900:<br>        return "CM" + recurse(num=
 - 900)<br><br>    elif num &gt;=3D 500:<br>        return "D" + recurse(nu=
m - 500)<br><br>    elif num &gt;=3D 400:<br>        return "CD" + recurse(=
num - 400)<br><br>    elif num &gt;=3D 100:<br>        return "C" + recurse=
(num - 100)<br><br>    elif num &gt;=3D 90:<br>        return "XC" + recurs=
e(num - 90)<br><br>    elif num &gt;=3D 50:<br>        return "L" + recurse=
(num - 50)<br><br>    elif num &gt;=3D 40:<br>        return "XL" + recurse=
(num - 40)<br><br>    elif num &gt;=3D 10:<br>        return "X" + recurse(=
num - 10)<br><br>    elif num &gt;=3D 9:<br>        return "IX" + recurse(n=
um - 9)<br><br>    elif num &gt;=3D 5:<br>        return "V" + recurse(num =
- 5)<br><br>    elif num &gt;=3D 4:<br>        return "IV" + recurse(num - =
4)<br><br>    elif num &gt;=3D 1:<br>        return "I" + recurse(num - 1)<=
br><br>    else:<br>        return ""<br><br>-Jeremy<br><br>[1]: <a href=3D=
"https://pypy=2Eorg/performance=2Ehtml#micro-tuning-tips">https://pypy=2Eor=
g/performance=2Ehtml#micro-tuning-tips</a><hr>pypy-dev mailing list -- pypy=
-dev@python=2Eorg<br>To unsubscribe send an email to pypy-dev-leave@python=
=2Eorg<br><a href=3D"https://mail=2Epython=2Eorg/mailman3/lists/pypy-dev=2E=
python=2Eorg/">https://mail=2Epython=2Eorg/mailman3/lists/pypy-dev=2Epython=
=2Eorg/</a><br>Member address: cfbolz@gmx=2Ede<br></div></pre></blockquote>=
</div></body></html>
------N3EJ7YSVNCRNXE67Y9FO567AT5J4FZ--

--===============4882256886515716948==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
pypy-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/pypy-dev.python.org/
Member address: [email protected]

--===============4882256886515716948==--