Generators vs. Functions?

Fredrik Lundh fredrik at pythonware.com
Sun Feb 5 03:49:21 EST 2006


Steven D'Aprano wrote:

> So on the basis of my tests, there is a small, but significant speed
> advantage to _calling_ a function versus _resuming_ a generator.

now add state handling to your micro-benchmark, and see if the function
example still runs faster.

(hint: functions and generators do different things, and are designed
for different use cases.  they're not two different ways to do the same
thing, and benchmarks that ignore that simple fact are pretty much use-
less, except, perhaps, for a very small group of VM developers.)

</F>






More information about the Python-list mailing list