PEP 255: Simple Generators

Roman Suzi rnd at
Mon Jun 25 00:34:34 EDT 2001

On Sun, 24 Jun 2001, Tim Peters wrote:

>[Roman Suzi, on my gcomb example]
>> This implementation is cool, but how fast will be recursive generators?
>> How large is the overhead to defrost execution frame each time? Will it
>> be faster than functional gcomb?

Well, of course memory usage of generators is minimal.
But the version I posted was made more compact because I used
list comprehension and no "insert", etc

Maybe there could be some reason to add "yield" in a
form of function also to make things like:

[ << x for i in .... ]

(here "<<" denotes proposed systax, unary "shift")
Or something like:

[yield(x) for x in ....]

Of course, I am aware that "yield" is flow control operator, but there are
equivalents of almost all other operators for use in functional style
programs. And it seems that to make them use generators will mean rewrite
them in .append/.extend/.insert fasion...

>On my box at the moment (Win98SE), the generator version below-- and on the
>test case shown --is about a 50% speedup over the recursive version (about
>.16 seconds for gcomb and .24 for rcomb).
>less-filling-and-tastes-great-ly y'rs  - tim
>PS:  In rcomb, a good speedup can be obtained by replacing
>        for c in rcomb(rest, k):
>            result.append(c)
>        result.extend(rcomb(rest, k))

Sincerely yours, Roman Suzi
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at _/
_/ Monday, June 25, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ "Darth Vader sleeps with a Teddywookie." _/

More information about the Python-list mailing list