mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-03 18:28:38 +00:00
feat(debug): added simple profile function
This commit is contained in:
parent
a54feeb55c
commit
e1f736d71f
1 changed files with 14 additions and 0 deletions
|
@ -36,4 +36,18 @@ function M.backtrace()
|
|||
Snacks.notify.warn(#trace > 0 and (table.concat(trace, "\n")) or "", { title = "Backtrace" })
|
||||
end
|
||||
|
||||
---@param fn fun()
|
||||
---@param opts? {count?: number, flush?: boolean}
|
||||
function M.profile(fn, opts)
|
||||
opts = vim.tbl_extend("force", { count = 100, flush = true }, opts or {})
|
||||
local start = vim.uv.hrtime()
|
||||
for _ = 1, opts.count, 1 do
|
||||
if opts.flush then
|
||||
jit.flush(fn, true)
|
||||
end
|
||||
fn()
|
||||
end
|
||||
Snacks.notify(((vim.uv.hrtime() - start) / 1e6 / opts.count) .. "ms")
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue