Quick actions

cmd+k|ctrl+k

Navigation

Languages

human

Snippet info

Language

Lua

Visibility

public

Author

captain.g

Created

2021-05-05T07:29:41.425634Z

Updated

2021-05-05T07:29:41.425634Z

local function human(n)
  if n == 0 or n >= 1 then
    return n.." s"
  elseif n >= 1e-3 then
    return (n*1e3).." ms"
  else
    return (n*1e6).." µs"
  end
end

assert(human(0) == "0 s")
assert(human(1) == "1 s")
assert(human(0.1) == "100 ms")
assert(human(0.001) == "1 ms")
assert(human(0.0001) == "100 µs")
assert(human(0.000001) == "1 µs")
assert(human(0.0000001) == "0.1 µs")
INFO