New submission from lvella <[email protected]>:

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 <[email protected]>
<https://bugs.pypy.org/issue1677>
________________________________________
_______________________________________________
pypy-issue mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-issue

Reply via email to