telescope-frecency.nvim/lua/frecency/timer.lua
JINNOUCHI Yasushi c140e6ff9c
feat: make query() faster and more lazier (#241)
* refactor: simplify logic to load web_devicons

* refactor: make register() asynchronous

* fix: load lazily modules outside this plugin

* refactor: simplify logic to wait initialization

* refactor: use uv.hrtime() instead of os.clock()

* fix: avoid errors in calling plenary.log in async

* test: store elapsed time to check in tests

* test: fix module names

This becomes a problem only in Ubuntu because macOS and Windows does not
care cases in filenames.

* test: fix types and unused modules

* style: fix by stylua

* refactor: make recency / entry_maker loaded lazily
2024-08-25 19:28:52 +09:00

27 lines
617 B
Lua

local config = require "frecency.config"
local log = require "frecency.log"
local uv = vim.uv or vim.loop
---@class FrecencyTimer
---@field elapsed number
---@field start integer
---@field title string
local Timer = {}
---@param title string
---@return FrecencyTimer
Timer.new = function(title)
return setmetatable({ start = uv.hrtime(), title = title }, { __index = Timer })
end
---@return nil
function Timer:finish()
if not config.debug then
return
end
self.elapsed = (uv.hrtime() - self.start) / 1000000000
log.debug(("[%s] takes %.3f seconds"):format(self.title, self.elapsed))
end
return Timer