[BangPypers] Performance benefits of Generators?

Chirayu Patel chirayu at chirayu.org
Tue Jun 30 12:20:26 CEST 2009

On Tue, Jun 30, 2009 at 3:36 PM, Amit Saha <amitsaha.in at gmail.com> wrote:
> Theoretically and/or practically, is it possible to reason about the
> performance gain/loss of using generators?  The PEP 255
> (http://www.python.org/dev/peps/pep-0255/) doesn't seem to hint at it.
> Anything that any of you would like to share on this ?

The most prevalent use case is in designs where a list generated by a
function is iterated over (third para of the PEP). Other couple of places
where I have used them are for tree traversal (instead of recursion), and as
generator expressions (instead of list comprehensions).

In all these three scenarios generators provide both CPU and memory
improvements over the traditional solutions.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/bangpypers/attachments/20090630/60e91913/attachment.htm>

More information about the BangPypers mailing list