aboutsummaryrefslogtreecommitdiff
path: root/src/ext/timeouts/bench/bench-expire.lua
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-04-13 08:58:43 -0400
committerNick Mathewson <nickm@torproject.org>2016-04-15 09:03:22 -0400
commit32e80ea3d32d5fd8207d16f9e5b26defa0d98a7c (patch)
treea8260d5422c2371c3b630d9435052ea299f15336 /src/ext/timeouts/bench/bench-expire.lua
parent0e354ad45966d29ff4cd75854dbd1715270a2168 (diff)
downloadtor-32e80ea3d32d5fd8207d16f9e5b26defa0d98a7c.tar.gz
tor-32e80ea3d32d5fd8207d16f9e5b26defa0d98a7c.zip
Import timeouts.c directly from William Ahern's git.
Imported from here: https://github.com/wahern/timeout Imported as of upstream e5a9e8bfaa9c631bdc54002181795931b65bdc1a. All sources unmodified.
Diffstat (limited to 'src/ext/timeouts/bench/bench-expire.lua')
-rwxr-xr-xsrc/ext/timeouts/bench/bench-expire.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/ext/timeouts/bench/bench-expire.lua b/src/ext/timeouts/bench/bench-expire.lua
new file mode 100755
index 0000000000..3e6374ed52
--- /dev/null
+++ b/src/ext/timeouts/bench/bench-expire.lua
@@ -0,0 +1,29 @@
+#!/usr/bin/env lua
+
+local bench = require"bench"
+local aux = require"bench-aux"
+
+local lib = ... or aux.optenv("BENCH_L", "bench-wheel.so")
+local limit = tonumber(aux.optenv("BENCH_N", 1000000))
+local step = tonumber(aux.optenv("BENCH_S", limit / 100))
+-- expire 1/1000 * #timeouts per clock update
+local exp_step = tonumber(aux.optenv("BENCH_E", 0.0001))
+local verbose = aux.toboolean(os.getenv("BENCH_V", false))
+
+local B = require"bench".new(lib, count)
+
+for i=0,limit,step do
+ -- add i timeouts
+ local fill_elapsed, fill_count, fill_last = aux.time(B.fill, B, i)
+
+ -- expire timeouts by iteratively updating clock. exp_step is the
+ -- approximate number of timeouts (as a fraction of the total number
+ -- of timeouts) that will expire per update.
+ local exp_elapsed, exp_count = aux.time(B.expire, B, fill_count, math.floor(fill_last * exp_step))
+ assert(exp_count == i)
+ assert(B:empty())
+ local exp_rate = i > 0 and i / exp_elapsed or 0
+
+ local fmt = verbose and "%d\t%f\t(%d/s)\t(fill:%f)" or "%d\t%f"
+ aux.say(fmt, i, exp_elapsed, exp_rate, fill_elapsed)
+end