瀏覽代碼

Script to compute perf

Hugo Musso Gualandi 4 年之前
父節點
當前提交
0bf129f605
共有 5 個文件被更改,包括 124 次插入29 次删除
  1. 48 0
      scripts/bench-parse-perf.lua
  2. 49 24
      scripts/bench-run.lua
  3. 26 0
      scripts/bench-sizes
  4. 0 4
      scripts/bench-tocsv.lua
  5. 1 1
      scripts/clean

+ 48 - 0
scripts/bench-parse-perf.lua

@@ -0,0 +1,48 @@
+#!/usr/bin/lua
+
+local pretty_names = {
+    binarytrees  = "Binary Trees",
+    fannkuch     = "Fannkuch",
+    fasta        = "Fasta",
+    knucleotide  = "K-Nucleotide",
+    mandelbrot   = "Mandelbrot",
+    nbody        = "N-Body",
+    spectralnorm = "Spectral Norm",
+}
+
+local function pretty_name(module)
+    local code, aot = string.match(module, "^(.*)(_cor)$")
+    local name = assert(pretty_names[code or module])
+    if aot then
+        return name .. " (AOT)"
+    else
+        return name .. " (Lua)"
+    end
+end
+
+while true do
+    local blank = io.read("l");
+    if not blank then break end
+    assert(blank == "")
+
+    local lines = {}
+    for i = 1, 18 do
+        lines[i] = io.read("l")
+    end
+
+    local module = assert(string.match(lines[1], "stats for .* (%S+) %d+ >"))
+    local cycle  = assert(string.match(lines[7], "(%S+) *cycles"))
+    local instr  = assert(string.match(lines[8], "(%S+) *instructions"))
+    local ipc    = assert(string.match(lines[8], "(%S+) *insn per cycle"))
+    local time   = assert(string.match(lines[12], "(%S+) *seconds time elapsed"))
+
+    local bench = pretty_name(module)
+    cycle = tonumber(cycle)
+    instr = tonumber(instr)
+    ipc   = tonumber(ipc)
+    time  = tonumber(time)
+
+    local sinstr = string.format("$%6.2f\\times10^9$", instr/1.0e9)
+    local scycle = string.format("$%6.2f\\times10^9$", cycle/1.0e9)
+    print(string.format("%-20s & %6.2f & %18s & %18s & %4.2f \\\\", bench, time, sinstr, scycle, ipc))
+end

+ 49 - 24
scripts/bench-run.lua

@@ -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

+ 26 - 0
scripts/bench-sizes

@@ -0,0 +1,26 @@
+#!/bin/sh
+
+measure() {
+    ls -lh "$@" | awk '{ print $5, $9 }'
+}
+
+# Compile
+for f in ./*.lua; do
+    ../src/luac -o "${f%.lua}.byte" "$f"
+done
+
+if ! test -f empty_aot.so; then
+    ../src/luaot empty.lua -o empty_aot.c
+    ../scripts/compile empty_aot.c
+fi
+
+echo "==== LUA SOURCE ===="
+measure -- *.lua
+
+echo
+echo "==== LUA BYTECODE ===="
+measure -- *.byte
+
+echo
+echo "==== AOT COMPILED ===="
+measure -- *_aot.so 

+ 0 - 4
scripts/bench-tocsv.lua

@@ -1,9 +1,5 @@
 #!/usr/bin/lua
 
-repeat
-    local line = io.read("*l")
-until line == "---START---"
-
 print("Benchmark,Implementation,N,Time")
 while true do
     local line1 = io.read("*l")

+ 1 - 1
scripts/clean

@@ -1,2 +1,2 @@
 #!/bin/sh -v
-rm -f ./*.c ./*.so
+rm -f ./*.c ./*.so ./*.byte