[pypy-issue] Issue #2770: python 3 code slower with pypy3 (pypy/pypy)
lesshaste
issues-reply at bitbucket.org
Sat Mar 3 12:32:49 EST 2018
New issue 2770: python 3 code slower with pypy3
https://bitbucket.org/pypy/pypy/issues/2770/python-3-code-slower-with-pypy3
lesshaste:
The following code was written by someone called Dennis.
from functools import lru_cache
@lru_cache(maxsize = None)
def haf(matrix):
n = len(matrix)
if n == 2: return matrix[0][1]
h = 0
for j in range(1, n):
if matrix[0][j] == 0: continue
copy = list(matrix)
del copy[:j+1:j]
copy = list(zip(*copy))
del copy[:j+1:j]
h += matrix[0][j] * haf(tuple(copy))
return h
If you feed into it the following input (for example):
[[0, -1, 0, 0, -1, 1, 1, -1, 1, -1, -1, 1, 1, 0, 1, 1, 1, 0, 1, -1, -1, 0, 0, -1, -1, 0], [-1, 1, 1, 1, -1, 1, -1, 0, 1, -1, 0, 0, -1, 0, 1, 1, 1, 0, 0, -1, 0, 0, -1, -1, -1, 0], [0, 1, 1, -1, 0, 0, 1, 0, 0, -1, 1, 0, -1, 1, -1, 0, 0, 0, -1, 0, 1, 0, 1, 1, 1, -1], [0, 1, -1, 0, -1, 0, 0, 1, 0, 0, -1, 1, 1, -1, -1, -1, 0, 1, -1, 1, -1, 0, 1, 0, 0, -1], [-1, -1, 0, -1, 1, 0, 1, 0, -1, 1, 1, -1, 0, -1, 0, 1, 1, -1, 0, -1, 1, 0, -1, 1, 1, -1], [1, 1, 0, 0, 0, 0, 0, -1, 1, 0, 0, 1, 0, -1, -1, -1, -1, 0, 0, -1, -1, 1, 1, 0, 1, 0], [1, -1, 1, 0, 1, 0, 0, 1, -1, -1, -1, 1, -1, -1, 0, -1, 1, 0, -1, 0, -1, -1, 0, -1, 0, -1], [-1, 0, 0, 1, 0, -1, 1, 0, 1, 0, 0, -1, -1, -1, 1, 0, 0, 1, -1, 1, 1, 0, -1, 0, -1, 1], [1, 1, 0, 0, -1, 1, -1, 1, 0, 0, -1, -1, -1, -1, 1, 1, 1, 1, -1, 1, -1, 1, -1, 1, 1, -1], [-1, -1, -1, 0, 1, 0, -1, 0, 0, 1, -1, 0, 1, 0, 0, 0, -1, -1, 0, -1, 1, 0, -1, -1, -1, 0], [-1, 0, 1, -1, 1, 0, -1, 0, -1, -1, 0, 1, 1, 0, 1, 0, 0, -1, -1, 1, 0, -1, 1, 1, 0, 0], [1, 0, 0, 1, -1, 1, 1, -1, -1, 0, 1, -1, 1, 0, -1, -1, 1, 1, 1, 0, 1, -1, -1, 0, -1, 1], [1, -1, -1, 1, 0, 0, -1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 0, 0, -1, 0, 0, -1, 1, -1], [0, 0, 1, -1, -1, -1, -1, -1, -1, 0, 0, 0, -1, 1, -1, 0, 1, -1, 0, 0, 1, -1, -1, 1, 1, 1], [1, 1, -1, -1, 0, -1, 0, 1, 1, 0, 1, -1, -1, -1, -1, 1, 1, -1, 0, 1, 1, 0, 0, -1, 0, 1], [1, 1, 0, -1, 1, -1, -1, 0, 1, 0, 0, -1, 1, 0, 1, 1, 0, 1, -1, 1, 1, 1, -1, 1, 1, -1], [1, 1, 0, 0, 1, -1, 1, 0, 1, -1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, -1, 0, 1, 0, 1, 0], [0, 0, 0, 1, -1, 0, 0, 1, 1, -1, -1, 1, -1, -1, -1, 1, 0, 0, -1, -1, 0, 0, 1, 1, 1, 0], [1, 0, -1, -1, 0, 0, -1, -1, -1, 0, -1, 1, 0, 0, 0, -1, 1, -1, -1, 1, 0, 1, -1, 0, -1, -1], [-1, -1, 0, 1, -1, -1, 0, 1, 1, -1, 1, 0, 0, 0, 1, 1, 0, -1, 1, 1, -1, -1, -1, -1, 0, 1], [-1, 0, 1, -1, 1, -1, -1, 1, -1, 1, 0, 1, -1, 1, 1, 1, -1, 0, 0, -1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 1, -1, 0, 1, 0, -1, -1, 0, -1, 0, 1, 0, 0, 1, -1, 1, -1, -1, 1, 1, 1], [0, -1, 1, 1, -1, 1, 0, -1, -1, -1, 1, -1, 0, -1, 0, -1, 1, 1, -1, -1, 1, -1, 0, -1, 0, 0], [-1, -1, 1, 0, 1, 0, -1, 0, 1, -1, 1, 0, -1, 1, -1, 1, 0, 1, 0, -1, 1, 1, -1, 0, 0, -1], [-1, -1, 1, 0, 1, 1, 0, -1, 1, -1, 0, -1, 1, 1, 0, 1, 1, 1, -1, 0, 0, 1, 0, 0, 1, -1], [0, 0, -1, -1, -1, 0, -1, 1, -1, 0, 0, 1, -1, 1, 1, -1, 0, 0, -1, 1, 0, 1, 0, -1, -1, 1]]
it takes about 10 seconds on python3 and about 14 seconds using pypy3.5-5.10.1-linux_x86_64-portable
More information about the pypy-issue
mailing list