[Python-ideas] A Continuations Compromise in Python
Robert Collins
robertc at robertcollins.net
Sun May 3 17:29:05 CEST 2009
On Mon, 2009-05-04 at 00:34 +1000, Steven D'Aprano wrote:
> Okay, this toy program isn't exactly a mission-critical application, but
> it does demonstrate a genuine performance penalty when using recursion.
> In this case, two recursive calls (one of which is a tail-call) takes
> nearly 60% more time than a single recursive call in a while loop.
This doesn't demonstrate where the issue is.
Is it function calls? The tail recursion call makes (eyeball count)
twice as many python function calls (not calls into generators) per call
to move(2)?
Or perhaps something else?
Sure, the TCO one is slower, but is the handing of result from generator
to generator really the issue? If it is rather something else, it may be
that the nested yielding while costing, is not costing
disproportionately - and is still a fraction of the cost.
python -m timeit 'from foo import do_move, do_move2' 'do_move()'
65535
10 loops, best of 3: 164 msec per loop
python -m timeit 'from foo import do_move, do_move2' 'do_move2()'
32768
10 loops, best of 3: 108 msec per loop
Half as many function calls, 2/3rds the time.
*Much* better measurement than these sketches is needed to say where the
issue is.
-Rob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.py
Type: text/x-python
Size: 796 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090504/2c7d1aee/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090504/2c7d1aee/attachment.pgp>
More information about the Python-ideas
mailing list