Generators vs. Functions?

Joseph Garvin k04jg02 at kzoo.edu
Sat Feb 4 15:28:35 EST 2006


Wolfgang Keller wrote:

>If this is actually also true in the general case, and not due to eventual 
>non-representativeness of the test mentioned above, is it simply due to a 
>less-than-optimum implementation of generators in the current Pyython 
>interpreter and thus likely to change in the future or is this a matter of 
>principle and will consequently remain like this forever?
>  
>

I am not a CPython or PyPy hacker, but I would guess that it will always 
be slower as a matter of principal. When resuming a generator you have 
to resetup the state the function was in when it was last called, which 
I think should always be more costly than calling the function with a 
clean state.

Someone want to correct me?

Whether or not the difference is that significant though I am unsure. It 
may be small enough that for most applications no one cares.



More information about the Python-list mailing list