develooper Front page | perl.perl5.porters | Postings from January 2001

Re: Can Perl do tail recursion?

Thread Previous | Thread Next
From:
Mark-Jason Dominus
Date:
January 24, 2001 11:24
Subject:
Re: Can Perl do tail recursion?
Message ID:
20010124192408.5648.qmail@plover.com

> But the following example does
> not seem to show the hope-for speedup of tail recursion:


In any case, I'm pretty sure we have had this conversation already.
You don't get a time optimization because goto & has large overhead.  
See http://www.plover.com/~mjd/misc/tail-recurse.pl for example.




> The slowness then characteristic speedup as @_ shrinks
> indicates that tail recursion is not happening.  

It's not really clear what you mean by 'tail recursion is not
happening'.  The conclusion I would draw from this is that the goto-&
operation is copying or relocating the argument vector, or performing
some other operation that is O(n) in the size of the argument vector.
But the stack remains constant size, as you can see from a perl -Ds
trace.


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About