run `$ ./src/luajit bench.lua 16 <path-to-payload>`. 16 is the recommended argument in `PARAM_x86.txt`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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