[pypy-issue] [issue980] Loop with small number of iterations much faster after unrolling
lesshaste
tracker at bugs.pypy.org
Wed Jan 4 20:16:31 CET 2012
New submission from lesshaste <drraph at gmail.com>:
In the following examples, the function hamdistX is called many times. If it is
implemented as a simple loop then it is 3 times slower than if the loop is
unrolled. In the case attached, the hamdistX loop only iterates 5 times. The
slow version is
def hamdist2(pattern, index, unknown):
"""Count the # of differences between equal length strings str1 and str2"""
diffs = 0
for i in xrange(l):
if pattern[i+index] != unknown[i]:
diffs += 1
return diffs
and the fast version is
def hamdist3(pattern, index, unknown):
"""Count the # of differences between equal length strings str1 and str2"""
diffs = 0
i = 0
if pattern[i+index] != unknown[i]:
diffs += 1
i += 1
if pattern[i+index] != unknown[i]:
diffs += 1
i += 1
if pattern[i+index] != unknown[i]:
diffs += 1
i += 1
if pattern[i+index] != unknown[i]:
diffs += 1
i += 1
if pattern[i+index] != unknown[i]:
diffs += 1
return diffs
----------
messages: 3635
nosy: lesshaste, pypy-issue
priority: performance bug
status: unread
title: Loop with small number of iterations much faster after unrolling
________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue980>
________________________________________
More information about the pypy-issue
mailing list