lua-users home
lua-l archive

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


Also, it seems like it would be more efficient to use a table directly for a couple of reasons. First, the special code that must have been in place to handle a table directly would be faster than having to make a function call every time.

I did a simple test. I timed the following scripts in 4.0.1, 5.0.2 and 5.1-alpha:

Lua 4.0.1 version:

    local t = {}
    for i = 1, 1e4 do t[i] = i*i end

    for i = 1, 1e4 do
      for k, v in t do end
    end

Lua 5.0.2 and 5.1-alpha version:

    local t = {}
    for i = 1, 1e4 do t[i] = i*i end

    for i = 1, 1e4 do
      for k, v in pairs(t) do end
    end

results:

Lua 4.0.1: ~7.3 seconds
Lua 5.0.2: ~15.2 seconds
Lua 5.1-alpha: ~16.1 seconds

(compiled with VC6, tested on a 2.6GHz Pentium 4)

--
Wim