lua-users home
lua-l archive

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

Geoff Leyland's recent post containing an example where LuaJIT
is 50 to 60 times faster than virtual-machine Lua, but C only 
1.06 times faster than LuaJIT, makes me wonder:

    Does the Lua/LuaJIT time ratio in general tell one how
    efficient Lua is relative to a near-optimal implementation?

To answer this, I tried a test in which all the time is spent inside 
string.match.  The attached file gave the following output on my machine:

$ lua timer.lua 
a   1.0053515434265
b   3.1299548149109

$ luajit timer.lua 
a   0.88654541969299
b   2.7685277462006

-- poor man's profiler via socket.gettime

require "socket"

tic = socket.gettime
times = {}

function profile(f,dt)
    times[f] = (times[f] or 0) + dt
function a()
    local t1 = tic()
    s = string.match(
    profile('a', tic()-t1)

function b()
    local t1 = tic()
    s = string.match(
    profile('b', tic()-t1)

for k=1,100000 do
    a(); b()

for k,v in pairs(times) do print(k,v) end