bench-expire.lua 1.0 KB

1234567891011121314151617181920212223242526272829
  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. -- expire 1/1000 * #timeouts per clock update
  8. local exp_step = tonumber(aux.optenv("BENCH_E", 0.0001))
  9. local verbose = aux.toboolean(os.getenv("BENCH_V", false))
  10. local B = require"bench".new(lib, count)
  11. for i=0,limit,step do
  12. -- add i timeouts
  13. local fill_elapsed, fill_count, fill_last = aux.time(B.fill, B, i)
  14. -- expire timeouts by iteratively updating clock. exp_step is the
  15. -- approximate number of timeouts (as a fraction of the total number
  16. -- of timeouts) that will expire per update.
  17. local exp_elapsed, exp_count = aux.time(B.expire, B, fill_count, math.floor(fill_last * exp_step))
  18. assert(exp_count == i)
  19. assert(B:empty())
  20. local exp_rate = i > 0 and i / exp_elapsed or 0
  21. local fmt = verbose and "%d\t%f\t(%d/s)\t(fill:%f)" or "%d\t%f"
  22. aux.say(fmt, i, exp_elapsed, exp_rate, fill_elapsed)
  23. end