lua-users home
lua-l archive

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


2010/11/24 Pierre-Yves Gérardy <pygy79@gmail.com>:
> However, they seem to be ambivalent on functions. Their semantics and
> implementation is excellent (first class, lexical scope with closure,
> tail call elimination) and invite to write functional code, yet the
> syntax makes it look like mud.

The semantics are even more excellent in 5.2 with (1) anonymous
function caching and (2) lightweight C functions.  So, things like the
mentioned "assertF(condition,\(costly result))" run faster:

  time lua -e 'local assert=assert; for i=1,1e7 do assert(true,
function() end) end'
  # 3.8 seconds - 5.1.4
  # 1.5 seconds - 5.2.0-work4
  # 1.7 seconds - luajit-2.0.0-beta5 (5.1.4)

  time lua -e 'local x = 0; for i=1,1e7 do x = x + (function(y) local
z = y*y; return z*z end)(i) end'
  # 4.0 seconds - 5.1.4
  # 2.2 seconds - 5.2.0-work4
  # 2.4 seconds - luajit-2.0.0-beta5 (5.1.4)
  time lua -e 'local x = 0; for i=1,1e7 do local z = i*i; x = x + z*z end'
  # 0.9 seconds - 5.1.4
  # 0.9 seconds - 5.2.0-work4
  # 0.1 seconds - luajit-2.0.0-beta5 (5.1.4)

I see 5.2 sometimes beating LuaJIT there ;)