|
@@ -1,18 +1,20 @@
|
|
|
#!/usr/bin/lua
|
|
|
|
|
|
local nkey = "slow"
|
|
|
+local mode = "time"
|
|
|
do
|
|
|
local i = 1
|
|
|
while i <= #arg do
|
|
|
if arg[i] == "--fast" then nkey = "fast"
|
|
|
elseif arg[i] == "--medium" then nkey = "medium"
|
|
|
elseif arg[i] == "--slow" then nkey = "slow"
|
|
|
+ elseif arg[i] == "--time" then mode = "time"
|
|
|
+ elseif arg[i] == "--perf" then mode = "perf"
|
|
|
end
|
|
|
i = i + 1
|
|
|
end
|
|
|
end
|
|
|
|
|
|
-local repetitions = 20
|
|
|
|
|
|
-- fast : runs on a blink of an eye (for testing / debugging)
|
|
|
-- medium : the aot version takes more than 1 second
|
|
@@ -32,7 +34,7 @@ local impls = {
|
|
|
{ name = "jit", suffix = "", interpreter = "luajit", compile = false },
|
|
|
{ name = "jof", suffix = "", interpreter = "luajit -j off", compile = false },
|
|
|
{ name = "lua", suffix = "", interpreter = "../src/lua", compile = false, },
|
|
|
- { name = "swt", suffix = "", interpreter = "../src/lua-sw", compile = false, },
|
|
|
+ { name = "lsw", suffix = "", interpreter = "../src/lua-sw", compile = false, },
|
|
|
{ name = "aot", suffix = "_aot", interpreter = "../src/lua", compile = "../src/luaot" },
|
|
|
{ name = "cor", suffix = "_cor", interpreter = "../src/lua", compile = "../src/luaot --coro" },
|
|
|
{ name = "trm", suffix = "_trm", interpreter = "../src/lua", compile = "../src/luaot-trampoline --coro"},
|
|
@@ -52,8 +54,12 @@ end
|
|
|
|
|
|
local function prepare(cmd_fmt, ...)
|
|
|
local params = table.pack(...)
|
|
|
- return (string.gsub(cmd_fmt, '%$(%d+)', function(i)
|
|
|
- return quote(params[tonumber(i)])
|
|
|
+ return (string.gsub(cmd_fmt, '([%%][%%]?)(%d*)', function(s, i)
|
|
|
+ if s == "%" then
|
|
|
+ return quote(params[tonumber(i)])
|
|
|
+ else
|
|
|
+ return "%"..i
|
|
|
+ end
|
|
|
end))
|
|
|
end
|
|
|
|
|
@@ -62,22 +68,23 @@ local function run(cmd_fmt, ...)
|
|
|
end
|
|
|
|
|
|
local function exists(filename)
|
|
|
- return run("test -f $1", filename)
|
|
|
+ return run("test -f %1", filename)
|
|
|
end
|
|
|
|
|
|
--
|
|
|
-- Recompile
|
|
|
--
|
|
|
|
|
|
-print("Recompiling the compiler...")
|
|
|
-assert(run("cd .. && make guess --quiet"))
|
|
|
+io.stderr:write("Recompiling the compiler...\n")
|
|
|
+assert(run("cd .. && make guess --quiet >&2"))
|
|
|
+io.stderr:write("...done\n")
|
|
|
|
|
|
for _, b in ipairs(benchs) do
|
|
|
for _, s in ipairs(impls) do
|
|
|
local mod = b.name .. s.suffix
|
|
|
if s.compile and not exists(mod .. ".so") then
|
|
|
- assert(run(s.compile .. " $1.lua -o $2.c", b.name, mod))
|
|
|
- assert(run("../scripts/compile $2.c", b.name, mod))
|
|
|
+ assert(run(s.compile.." %1.lua -o %2.c", b.name, mod))
|
|
|
+ assert(run("../scripts/compile %2.c", b.name, mod))
|
|
|
end
|
|
|
end
|
|
|
end
|
|
@@ -86,26 +93,44 @@ end
|
|
|
-- Execute
|
|
|
--
|
|
|
|
|
|
-print("---START---")
|
|
|
+local function bench_cmd(b, impl)
|
|
|
+ local module
|
|
|
+ if string.match(impl.interpreter, "luajit") and exists(b.name.."_jit.lua") then
|
|
|
+ module = b.name .. "_jit"
|
|
|
+ else
|
|
|
+ module = b.name .. impl.suffix
|
|
|
+ end
|
|
|
|
|
|
-for _, b in ipairs(benchs) do
|
|
|
- for _, s in ipairs(impls) do
|
|
|
+ local n = assert(b[nkey])
|
|
|
+ return prepare(impl.interpreter .. " main.lua %1 %2 > /dev/null", module, n)
|
|
|
+end
|
|
|
|
|
|
- local mod
|
|
|
- if string.match(s.interpreter, "luajit") and exists(b.name.."_jit.lua") then
|
|
|
- mod = b.name .. "_jit"
|
|
|
- else
|
|
|
- mod = b.name .. s.suffix
|
|
|
+if mode == "time" then
|
|
|
+
|
|
|
+ for _, b in ipairs(benchs) do
|
|
|
+ for _, impl in ipairs(impls) do
|
|
|
+ local cmd = bench_cmd(b, impl)
|
|
|
+ for rep = 1, 20 do
|
|
|
+ print(string.format("RUN %s %s %s", b.name, impl.name, rep))
|
|
|
+ assert(run("/usr/bin/time -p sh -c %1 2>&1", cmd))
|
|
|
+ print()
|
|
|
+ end
|
|
|
end
|
|
|
+ end
|
|
|
|
|
|
- local n = assert(b[nkey])
|
|
|
- local cmd = prepare(s.interpreter .. " main.lua $1 $2 > /dev/null", mod, n)
|
|
|
+elseif mode == "perf" then
|
|
|
|
|
|
- for rep = 1, repetitions do
|
|
|
- print(string.format("RUN %s %s %s", b.name, s.name, rep))
|
|
|
- assert(run("/usr/bin/time -p sh -c $1 2>&1", cmd))
|
|
|
- print()
|
|
|
+ for _, b in ipairs(benchs) do
|
|
|
+ for _, impl in ipairs(impls) do
|
|
|
+ if impl.name == "lua" or impl.name == "cor" then
|
|
|
+ local cmd = bench_cmd(b, impl)
|
|
|
+ --print(string.format("RUN %s %s %s", b.name, impl.name, rep))
|
|
|
+ assert(run("LANG=C perf stat sh -c %1 2>&1", cmd))
|
|
|
+ print()
|
|
|
+ end
|
|
|
end
|
|
|
end
|
|
|
-end
|
|
|
|
|
|
+else
|
|
|
+ error("impossible")
|
|
|
+end
|