Merge branch 'maint-0.4.8'
[tor.git] / src / ext / timeouts / bench / bench-aux.lua
blob6321247421939c864c25eb38b2db2b8d4e476706
1 local bench = require"bench"
2 local clock = bench.clock
4 local aux = {}
6 local function time_return(begun, ...)
7 local duration = clock() - begun
8 return duration, ...
9 end
11 function aux.time(f, ...)
12 local begun = clock()
13 return time_return(begun, f(...))
14 end
16 function aux.say(...)
17 print(string.format(...))
18 end
20 function aux.toboolean(s)
21 return tostring(s):match("^[1TtYy]") and true or false
22 end
24 function aux.optenv(k, def)
25 local s = os.getenv(k)
27 return (s and #s > 0 and s) or def
28 end
30 return aux