wrapping yield ?

Oren Tirosh oren-py-l at hishome.net
Fri Sep 13 17:20:53 EDT 2002


On Fri, Sep 13, 2002 at 01:01:15PM +0000, Duncan Booth wrote:
> Don't forget that iterating with a generator is *much* more efficient than 
> calling a Python functions thousands of times.
> 
> Python has a big overhead on each function call, but you only pay that 
> overhead when you first call a generator and the subsequent iterations have 
> virtually no overhead at all. 

In most programming environments function calls are fast and context
switches are slow. Python is quite unusual in having it the other way 
around - a yield statement causes a context switch that is much faster 
than a function call.

	Oren




More information about the Python-list mailing list