Files
dep/lua/dep/bench.lua

33 lines
639 B
Lua

-- TODO: actually use this (ideally make a view that shows startuptime and
-- which plugins are currently loaded)
-- performance logging
---@class bench
---@field perf number[] list of all perfs
local bench = {}
local b
function bench.setup()
local o = {}
o.perf = {}
o.inited = true
b = o
end
--- benchmark a peice of code
---@param name string the name of the benchmark
---@param f function the code to benchmark
---@vararg any args for f
---@return any ret the result of f
function bench.mark(name, f, ...)
local start = os.clock()
local ret = f(...)
b.perf[name] = os.clock() - start
return ret
end
return bench