[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: When is Lua already very efficient by itself?
- From: Dirk Laurie <dpl@...>
- Date: Tue, 23 Aug 2011 10:07:40 +0200
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
Dirk
-- poor man's profiler via socket.gettime
require "socket"
tic = socket.gettime
times = {}
function profile(f,dt)
times[f] = (times[f] or 0) + dt
end
function a()
local t1 = tic()
s = string.match(
"abcdefghijklmnopqrstuvwxyz",".*1")
profile('a', tic()-t1)
end
function b()
local t1 = tic()
s = string.match(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",".*1")
profile('b', tic()-t1)
end
for k=1,100000 do
a(); b()
end
for k,v in pairs(times) do print(k,v) end