On 03/08/10 04:45, Guido van Rossum wrote:
It remains to be seen at which point this becomes prohibitive and when the overhead of wrapping every generator in a From instance (and passing every next() call through a method of that instance) is actually faster, given that a for-loop iteration is just a few bytecode instructions.
I don't know about the trampoline-style implementations that have been posted, but I did some timings with my yield-from implementation, and it seems that delegating a next() call via yield-from has only about 8% of the overhead of doing the same with a for-loop.
I also tried an experiment where I traversed a binary tree using recursive generators and yield-from. For a tree depth of 20, the whole thing was between 2 and 3 times faster than using for-loops.