tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

bench-expire.lua (1070B)


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