On 18/09/2024 05.43, Jeremy Brown 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. One major
headscratcher is that CPython runtimes hold stable while PyPy appears
to get worse as the benchmark progresses.
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). [1]
Hi Jeremy,
The page you linked
(https://pypy.org/performance.html#string-concatenation-is-expensive) says:
“PyPy's JIT makes the overhead of intermediate concatenations go away in
linear code that keeps the number of concatenations small, bound and
constant”
Your code is not linear and the number of concatenations is not bounded.
“On the other hand, in code like this with a string-valued foo()
function: [code example] the JIT cannot optimize out intermediate
copies. This code is actually quadratic in the total size of the mylist
strings due to repeated string copies of ever-larger prefix segments.”
Your code is more similar to the code example that shows a case where
the optimization doesn’t work.
Does that explain the behavior you’re seeing? Feel free to make
suggestions on how to clarify the wording.
-Manuel
def recurse(num):
if num >= 1000:
return "M" + recurse(num - 1000)
elif num >= 900:
return "CM" + recurse(num - 900)
elif num >= 500:
return "D" + recurse(num - 500)
elif num >= 400:
return "CD" + recurse(num - 400)
elif num >= 100:
return "C" + recurse(num - 100)
elif num >= 90:
return "XC" + recurse(num - 90)
elif num >= 50:
return "L" + recurse(num - 50)
elif num >= 40:
return "XL" + recurse(num - 40)
elif num >= 10:
return "X" + recurse(num - 10)
elif num >= 9:
return "IX" + recurse(num - 9)
elif num >= 5:
return "V" + recurse(num - 5)
elif num >= 4:
return "IV" + recurse(num - 4)
elif num >= 1:
return "I" + recurse(num - 1)
else:
return ""
-Jeremy
[1]: https://pypy.org/performance.html#micro-tuning-tips
_______________________________________________
pypy-dev mailing list -- pypy-dev@python.org
To unsubscribe send an email to pypy-dev-le...@python.org
https://mail.python.org/mailman3/lists/pypy-dev.python.org/
Member address: m...@manueljacob.de
_______________________________________________
pypy-dev mailing list -- pypy-dev@python.org
To unsubscribe send an email to pypy-dev-le...@python.org
https://mail.python.org/mailman3/lists/pypy-dev.python.org/
Member address: arch...@mail-archive.com