Skip to content

Instantly share code, notes, and snippets.

@Shishqa
Created July 28, 2021 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shishqa/d8e29f501d72647878b8993a206cea19 to your computer and use it in GitHub Desktop.
Save Shishqa/d8e29f501d72647878b8993a206cea19 to your computer and use it in GitHub Desktop.
run `$ ./src/luajit bench.lua 16 <path-to-payload>`. 16 is the recommended argument in `PARAM_x86.txt`
local misc = require("misc")
local jit = require("jit")
local os = require("os")
local io = require("io")
local N_RUNS = 15
local function avg(n, func)
local sum = 0
for _ = 1, n do
local old_out = io.output()
io.output("/dev/null")
jit.flush()
collectgarbage()
local start = os.clock()
func()
local stop = os.clock()
sum = sum + (stop - start)
io.output(old_out)
print(' -> '..(stop - start))
io.flush()
end
print(' avg: '..(sum / n))
io.flush()
end
local function run_bench()
avg(N_RUNS, function()
local payload = assert(loadfile(arg[#arg]))
local res, err = misc.memprof.start('/dev/null')
assert(res, err)
payload()
res, err = misc.memprof.stop()
assert(res, err)
end)
end
print('JIT-OFF')
jit.off()
run_bench()
print('JIT-ON')
jit.on()
run_bench()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment