[pypy-issue] Issue #2104: Pypy3 2.4.0 slower than Python 3.4.2 for a function? (pypy/pypy)

TheLoneWolfling . issues-reply at bitbucket.org
Sun Aug 2 16:59:29 CEST 2015

New issue 2104: Pypy3 2.4.0 slower than Python 3.4.2 for a function?

TheLoneWolfling .:

With the following code:


import random, itertools, timeit

def atLeast(a,b,num):
    return sum(x==y for x,y in itertools.zip_longest(reversed(bin(a).partition('b')[-1]), reversed(bin(b).partition('b')[-1]), fillvalue='0')) >= num

print(timeit.timeit(stmt='atLeast(a,b,96)', setup='from __main__ import atLeast\nimport random\na=random.getrandbits(128)\nb=random.getrandbits(128)', number=100000))

I get the following:


C:\>python -V
Python 3.4.2

C:\>pypy -V
Python 3.2.5 (b2091e973da6, Oct 19 2014, 21:25:51)
[PyPy 2.4.0 with MSC v.1500 32 bit]

C:\>python pypyslow.py

C:\>pypy.exe pypyslow.py
Note that Pypy is actually *slower* at running this function than stock Python is.

(I am aware that this is a really bad way to write this function, however I know PyPy likes to know about performance regressions. Just because this function is bad doesn't necessarily mean that there aren't any other functions that are well-written that exhibit this same problem.)

May be related to #2100.

More information about the pypy-issue mailing list