[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: tail call efficiency (was: Modified allwords() function)
- From: Wim Couwenberg <wcou@...>
- Date: Tue, 17 May 2005 14:32:50 +0200
I another post Mike Pall profiled coroutine code and found that it uses
more time then he'd like:
> Especially because the latter needs an additional call
> frame (which could be improved by making yield a keyword/VM op).
On a related note, I wonder if it would be at all possible to optimise
tailcalls any further? Consider the following functions to sum an
arithmetic sequence:
local function sumi(n, r)
while r > 0 do
n = n + r
r = r - 1
end
return n
end
local function sumr(n, r)
if r > 0 then
return sumr(n + r, r - 1)
end
return n
end
The recursive sumr takes about 2.5 times more time than the iterative
sumi in 5.0.2. (In 5.1-w5 both are quicker, but the iterative version
more so than the recursive one...) If tailcalls get cheaper, they would
gain in strength as "structured goto's".
Just wishful thinking probably... ;-)
--
Wim