bench-aux.lua 507 B

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