feat(debug): profile title

This commit is contained in:
Folke Lemaitre 2024-11-21 22:08:46 +01:00
parent 33d31af150
commit 017707955f
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -51,7 +51,7 @@ end
-- * **flush**: set to `true` to use `jit.flush` in every iteration. -- * **flush**: set to `true` to use `jit.flush` in every iteration.
-- * **count**: defaults to 100 -- * **count**: defaults to 100
---@param fn fun() ---@param fn fun()
---@param opts? {count?: number, flush?: boolean} ---@param opts? {count?: number, flush?: boolean, title?: string}
function M.profile(fn, opts) function M.profile(fn, opts)
opts = vim.tbl_extend("force", { count = 100, flush = true }, opts or {}) opts = vim.tbl_extend("force", { count = 100, flush = true }, opts or {})
local start = uv.hrtime() local start = uv.hrtime()
@ -61,7 +61,7 @@ function M.profile(fn, opts)
end end
fn() fn()
end end
Snacks.notify(((uv.hrtime() - start) / 1e6 / opts.count) .. "ms") Snacks.notify(((uv.hrtime() - start) / 1e6 / opts.count) .. "ms", { title = opts.title or "Profile" })
end end
-- Log a message to the file `./debug.log`. -- Log a message to the file `./debug.log`.