Message228151
Found another example that shows horrible performance when using itertools.product:
def gen():
l = [itertools.permutations(range(10)) for _ in range(10)]
g = itertools.product(*l)
for i in g:
yield i
A simple next() to this generator takes 16 seconds on my desktop.
I use this recursive product() instead and the performance is acceptable:
def product(*args):
if len(args) == 1:
for i in args[0]:
yield [i]
else:
for i in args[0]:
for j in product(*args[1:]):
j.append(i)
yield j |
|
Date |
User |
Action |
Args |
2014-10-02 03:08:02 | yegle | set | recipients:
+ yegle, rhettinger, terry.reedy, falsetru, eric.araujo, Sumudu.Fernando |
2014-10-02 03:08:02 | yegle | set | messageid: <1412219282.67.0.95935303068.issue10109@psf.upfronthosting.co.za> |
2014-10-02 03:08:02 | yegle | link | issue10109 messages |
2014-10-02 03:08:02 | yegle | create | |
|