summaryrefslogtreecommitdiff
path: root/bindings/rs-timeout/timeout/bench/bench-aux.lua
diff options
context:
space:
mode:
author张杨 <[email protected]>2023-10-18 03:35:17 +0000
committer陆秋文 <[email protected]>2023-10-18 03:35:17 +0000
commitecc6d08170d6f4914fd90bf9fe574c657546cfae (patch)
treeb1a45b2f671d3213347be268c5787eebba1ff5b8 /bindings/rs-timeout/timeout/bench/bench-aux.lua
parent36450f5dfa230ef806151101ee8047375915ad73 (diff)
merge bind-rs-timeoutHEADmain
Diffstat (limited to 'bindings/rs-timeout/timeout/bench/bench-aux.lua')
-rw-r--r--bindings/rs-timeout/timeout/bench/bench-aux.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/bindings/rs-timeout/timeout/bench/bench-aux.lua b/bindings/rs-timeout/timeout/bench/bench-aux.lua
new file mode 100644
index 0000000..6321247
--- /dev/null
+++ b/bindings/rs-timeout/timeout/bench/bench-aux.lua
@@ -0,0 +1,30 @@
+local bench = require"bench"
+local clock = bench.clock
+
+local aux = {}
+
+local function time_return(begun, ...)
+ local duration = clock() - begun
+ return duration, ...
+end
+
+function aux.time(f, ...)
+ local begun = clock()
+ return time_return(begun, f(...))
+end
+
+function aux.say(...)
+ print(string.format(...))
+end
+
+function aux.toboolean(s)
+ return tostring(s):match("^[1TtYy]") and true or false
+end
+
+function aux.optenv(k, def)
+ local s = os.getenv(k)
+
+ return (s and #s > 0 and s) or def
+end
+
+return aux