Files
neovim/test/benchmark/keycodes_spec.lua
Justin M. Keyes 6d8c8b18d5 test(harness): migrate away from magic globals
Problem:
The magic globals `it`, `describe`, etc., are more trouble than they are
worth.

- Hooking into `after_each` requires `getfenv()` hacks.
- They confuse luals/emmylua, because the top-level `.luarc.json` isn't
  merged with `test/.luarc.json` (apparently a luals limitation?)
- They totally defeat discoverability because the user just has to
  "know" about the various magic symbols.

So they harm DX, which means they serve no purpose at all.

Solution:
- Expose the test API from `testutil`, so tests can call `t.it()`,
  `t.describe()`, etc., in the conventional way.
- Drop `getfenv()` hacks.
- Drop the `setfenv()` injection in `load_chunk`.
- Drop `test/_meta.lua`.
2026-07-21 13:22:39 +02:00

61 lines
1.6 KiB
Lua

local n = require('test.functional.testnvim')()
local t = require('test.testutil')
local describe, it = t.describe, t.it
local clear = n.clear
local api = n.api
local fn = n.fn
local keycodes = require('src.nvim.keycodes')
describe('nvim_replace_termcodes performance', function()
it('200 calls with a key repeated 5000 times', function()
clear()
local stats = {}
local ms = 1 / 1000000
for _, keycode in ipairs(keycodes.names) do
local notation = ('<%s>'):format(keycode[2])
local str = notation:rep(5000)
local start = vim.uv.hrtime()
for _ = 1, 200 do
api.nvim_replace_termcodes(str, false, true, true)
end
local elapsed = vim.uv.hrtime() - start
table.insert(stats, elapsed)
io.stdout:write(('\n%-20s%14.6f ms'):format(notation, elapsed * ms))
io.stdout:flush()
end
io.stdout:write('\n')
t.bench_report(stats, { unit = 'ms' })
end)
end)
describe('keytrans() performance', function()
it('200 calls with a key repeated 5000 times', function()
clear()
local stats = {}
local ms = 1 / 1000000
for _, keycode in ipairs(keycodes.names) do
local notation = ('<%s>'):format(keycode[2])
local str = api.nvim_replace_termcodes(notation, false, true, true):rep(5000)
local start = vim.uv.hrtime()
for _ = 1, 200 do
fn.keytrans(str)
end
local elapsed = vim.uv.hrtime() - start
table.insert(stats, elapsed)
io.stdout:write(('\n%-20s%14.6f ms'):format(notation, elapsed * ms))
io.stdout:flush()
end
io.stdout:write('\n')
t.bench_report(stats, { unit = 'ms' })
end)
end)