Why is appending to a string so much slower in PyPy than in CPython?

404 views Asked by At

I have this relatively simple Python program

inpt = "0"*1000000
out = ""

for x in inpt:
    out += x

When I run it using the default Python 2.7.9, it finishes relatively quickly:

time python te.py
0.27s user 0.02s system 93% cpu 0.308 total

When I run it using PyPy 5.6.0, it goes from taking less than half a second to taking nearly a minute and a half:

time pypy te.py
85.73s user 15.40s system 95% cpu 1:45.53 total

What could be causing this dramatic slowdown? I usually use PyPy to speed up my Python code, but this result surprises me.

0

There are 0 answers