Skip to content

Commit

Permalink
(mini.misc) Update bench_time() to use vim.loop.hrtime().
Browse files Browse the repository at this point in the history
  • Loading branch information
echasnovski committed Dec 29, 2023
1 parent 937386c commit 02f5c05
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ vim.keymap.set('i', '<C-z>', '<C-g>u<Esc>[s1z=`]a<C-g>u', { desc = 'Correct late
- BREAKING: Update default `write_post` hook to not display current time in success message.
- Update to include space before `~` in generated section headings.

## mini.misc

- Update `bench_time()` to use `vim.loop.hrtime()` (as better designed for benchmarking) instead of `vim.loop.gettimeofday()`.

## mini.sessions

- FEATURE: Update `read()` to first `write()` current session (if there is any).
Expand Down
2 changes: 1 addition & 1 deletion doc/mini-misc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Parameters ~
{...} `(any)` Arguments when calling `f`.

Return ~
`(...)` Table with durations (in seconds; up to microseconds) and
`(...)` Table with durations (in seconds; up to nanoseconds) and
output of (last) function execution.

------------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions lua/mini/misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ MiniMisc.config = {
---@param n number|nil Number of times to execute `f(...)`. Default: 1.
---@param ... any Arguments when calling `f`.
---
---@return ... Table with durations (in seconds; up to microseconds) and
---@return ... Table with durations (in seconds; up to nanoseconds) and
--- output of (last) function execution.
MiniMisc.bench_time = function(f, n, ...)
n = n or 1
local durations, output = {}, nil
for _ = 1, n do
local start_sec, start_usec = vim.loop.gettimeofday()
local start_time = vim.loop.hrtime()
output = f(...)
local end_sec, end_usec = vim.loop.gettimeofday()
table.insert(durations, (end_sec - start_sec) + 0.000001 * (end_usec - start_usec))
local end_time = vim.loop.hrtime()
table.insert(durations, 0.000000001 * (end_time - start_time))
end

return durations, output
Expand Down

0 comments on commit 02f5c05

Please sign in to comment.