Use of generators and efficiency

Tim Chase python.list at tim.thechases.com
Wed Sep 17 07:21:19 EDT 2008


> To my great surprise, this approach was often considerably _slower_  to 
> complete than the original program (up to ~40% depending on which modifiers 
> were used), despite producing initial results more quickly.

You may be interested in reading through this thread

http://mail.python.org/pipermail/python-list/2008-January/473650.html

where looping vs generators were timed and you can see that 
generators clearly (and sadly) impose a speed penalty as 
demonstrated by Andrew Reedick.  I'm not sure whether the "why" 
of it was ever determined, but generators should be used with 
care if speed is more important than clarity.

-tkc






More information about the Python-list mailing list