[pypy-issue] [issue1677] itertools.product slower than nested fors
lvella
tracker at bugs.pypy.org
Sat Jan 18 21:17:58 CET 2014
New submission from lvella <lvella at gmail.com>:
Consider the 2 following snippets:
a)
n = 0.0
for i in xrange(1000):
for j in xrange(1000):
for k in xrange(1000):
n += float(i) * j * k
print n
b)
import itertools
n = 0.0
for i,j,k in itertools.product(xrange(1000), xrange(1000), xrange(1000)):
n += float(i) * j * k
print n
I find snippet b) much nicer to read and write, but it is sad that b) is much
slower than a):
execution of a):
$ time pypy loop.py
1.24625374875e+17
real 0m7.877s
user 0m7.853s
sys 0m0.020s
execution of b):
$ time pypy loop.py
1.24625374875e+17
real 0m38.214s
user 0m38.209s
sys 0m0.008s
So, can this be fixed, so both have the good speed of a)?
----------
messages: 6496
nosy: lvella, pypy-issue
priority: feature
status: unread
title: itertools.product slower than nested fors
________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue1677>
________________________________________
More information about the pypy-issue
mailing list