Sun, 28 Apr 2002 23:04:04 -0400
From: "Guido van Rossum" <email@example.com>
> > I'm already working on a separate module for iterators galore
> > (and will cross-check to Haskell to make sure I didn't miss anything).
> > I posted this one separately because zip() eats memory like crazy
> > and because a Python generator version crawls like a snail.
> Do you have use cases where the memory use matters? I.e. where it
> needs more memory than you have RAM?
No. Am I'm not proposing a backport to Pippy ;)
> > IMHO, This is a better way to loop over multiple sequences and
> > has a chance at becoming the tool of choice. I scanned all of my
> > Python code and found that iterzip() was a better choice in every
> > case except a matrix transpose coded as zip(*mat).
> Did you time any of these?
I just timed it and am shocked. iterzip() has exactly the same code
as zip() except for the final append result to list. So, I expected only
a microscopic speed-up. I don't see where the huge performance
improvement came from.
# time iterzip
from __future__ import generators
def run(f, iterables):
start = time.time()
for tup in f(*iterables):
return time.time() - start
iterables = map(iter, iterables)
yield tuple([i.next() for i in iterables])
n = 1000000
for f in [zip, iterzip, genzip]:
print run(f, [xrange(n), xrange(n), xrange(n)]), f.__name__