lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Pierre-Yves Gérardy wrote:
> * _while() is almost as fast as a vanilla while loop in LuaJIT

No, both generate the same code and are the same speed. Your
measurements are too short and your system does not provide enough
timing accuracy (desktop Linux nowadays uses 250Hz => 4ms).

> * the overhead of a tail call relative to a while loop (test 3 and 2
> respectively) is only halved in LuaJIT, which is far from the gains it
> provides usually.
> 
> The first two points are just amazing, but the third one is
> puzzling... Is there somthing inherently slow in the elimination of
> tail calls? Or hasn't it been optimized [ yet | on purpose ]?

Sure, it does tail call elimination. But that's an entirely
different matter than compiling tail-recursion. It's running in
the interpreter right now (still 6x faster than Lua).

Quoting: http://luajit.org/status.html
  "Recursion is not traced yet."

That said, I'm working on it right now. All loops run the same
speed in my work branch (not pushed yet):

$ TIMEFORMAT="%U"
$ time luajit while.lua
0.012
$ time luajit _while.lua
0.012
$ time luajit _while_recursive.lua
0.012

--Mike