bench-aux.lua (507B)
1 local bench = require"bench" 2 local clock = bench.clock 3 4 local aux = {} 5 6 local function time_return(begun, ...) 7 local duration = clock() - begun 8 return duration, ... 9 end 10 11 function aux.time(f, ...) 12 local begun = clock() 13 return time_return(begun, f(...)) 14 end 15 16 function aux.say(...) 17 print(string.format(...)) 18 end 19 20 function aux.toboolean(s) 21 return tostring(s):match("^[1TtYy]") and true or false 22 end 23 24 function aux.optenv(k, def) 25 local s = os.getenv(k) 26 27 return (s and #s > 0 and s) or def 28 end 29 30 return aux