bench-add.lua 989 B

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