
Jacob Holm wrote:
Arnaud Delobelle wrote:
* What you are measuring the time complexity of.
The time for a single 'next', 'send', 'throw' or 'close' call to a generator or a single "yield from" expression,
How are you measuring 'time', though? Usually when discussing time complexities we're talking about the number of some fundamental operation being performed, and assuming that all such operations take the same time. What operations are you counting here?
One interesting thing to note is that all non-contrived examples I have seen only build simple chains of iterators, and only do that by adding one at a time in the deepest nested one. This is the best possible case for my algorithm. If you stick to that, the time per operation is O(1).
I don't understand that limitation. If you keep a stack of active generators, you always have constant-time access to the one to be resumed next. There's some overhead for pushing and popping the stack, but it follows exactly the same pattern as the recursive calls you'd be making if you weren't using some kind of yield-from, so it's irrelevant when comparing the two. -- Greg