Skip to content

Instantly share code, notes, and snippets.

@dvv
Last active December 28, 2015 09:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvv/7480842 to your computer and use it in GitHub Desktop.
Save dvv/7480842 to your computer and use it in GitHub Desktop.
Lua perf measurement
#!/usr/bin/env le-lua-interpreter
if #arg < 1 then
-- TODO: help
os.exit(1)
end
local DEFAULT_ITERATIONS = 1e6
local bench_file = arg[1]
local iterations = tonumber(arg[2])
local case_name = arg[3]
local cases = assert(assert(loadfile(bench_file))())
-- measure cases, one by one in own processes
if not case_name then
for name, _ in pairs(cases) do
-- TODO: we can get anything else by tuning format
os.execute("/usr/bin/time -f 'dry_" .. name .. "=%e' " .. arg[0] .. " " .. bench_file .. " 0 " .. " " .. name)
os.execute("/usr/bin/time -f 'run_" .. name .. "=%e' " .. arg[0] .. " " .. bench_file .. " " .. (iterations or "=") .. " " .. name)
end
os.exit(0)
end
-- measure one case
local case = cases[case_name]
if type(case) == "table" then
if case.setup then
case.setup()
end
local fn = assert(case.fn)
local n = iterations or case.iterations or DEFAULT_ITERATIONS
for i = 1, n do
fn()
end
if case.teardown then
case.teardown()
end
else
local fn = assert(case)
local n = iterations or DEFAULT_ITERATIONS
for i = 1, n do
fn()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment