[BangPypers] Performance benefits of Generators?

Venkatraman S venkat83 at gmail.com
Tue Jun 30 12:23:06 CEST 2009

On Tue, Jun 30, 2009 at 3:37 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.
> Since, this is out of mere curiosity, for the moment, performance
> would be simply the time taken to complete a task.

Check out David Beazley's(dabeaz) article on Generators.

OTOH, Decorators , lambdas ('syntactic sugars') et al reduce the number of
lines of code,
depending on the scenario, for a given piece of complex logic, but these are
'slow'. But, I dont think
the factor is huge enough to cause a performance bottleneck.  I had similar
reservations on
list comprehensions, but in some cases the bytecode generated by LC is same
as the one generated
by the if-else/loop counterparts. If you are building apps wherein  every
microsecond matters,
then it is better to time both variants - the sugars and their vanilla
equivalents - and then choose the best.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/bangpypers/attachments/20090630/489b524d/attachment.htm>

More information about the BangPypers mailing list