bench-add.lua (989B)
1 #!/usr/bin/env lua 2 3 local bench = require"bench" 4 local aux = require"bench-aux" 5 6 local lib = ... or aux.optenv("BENCH_L", "bench-wheel.so") 7 local limit = tonumber(aux.optenv("BENCH_N", 1000000)) 8 local step = tonumber(aux.optenv("BENCH_S", limit / 100)) 9 local exp_step = tonumber(aux.optenv("BENCH_E", 1.0)) 10 local verbose = aux.toboolean(os.getenv("BENCH_V", false)) 11 12 local B = bench.new(lib, count, nil, verbose) 13 local fill_count, fill_last = B:fill(limit) 14 15 for i=0,limit,step do 16 local exp_elapsed, fill_elapsed, fill_rate 17 18 -- expire all timeouts 19 --exp_elapsed = aux.time(B.expire, B, fill_count, fill_last * exp_step) 20 exp_elapsed = aux.time(B.del, B, 0, fill_count) 21 assert(B:empty()) 22 23 -- add i timeouts 24 fill_elapsed, fill_count, fill_last = aux.time(B.fill, B, i) 25 assert(fill_count == i) 26 fill_rate = fill_elapsed > 0 and (fill_count / fill_elapsed) or 0 27 28 local fmt = verbose and "%d\t%f\t(%d/s)\t(exp:%f)" or "%d\t%f" 29 aux.say(fmt, i, fill_elapsed, fill_rate, exp_elapsed) 30 end