2023-04-27 10:25:08 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
|
|
|
|
local clear = helpers.clear
|
|
|
|
local exec_lua = helpers.exec_lua
|
|
|
|
|
|
|
|
local N = 7500
|
|
|
|
|
|
|
|
describe('autocmd perf', function()
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
|
|
|
|
exec_lua([[
|
|
|
|
out = {}
|
|
|
|
function start()
|
2023-06-03 03:06:00 -07:00
|
|
|
ts = vim.uv.hrtime()
|
2023-04-27 10:25:08 -07:00
|
|
|
end
|
|
|
|
function stop(name)
|
2023-06-03 03:06:00 -07:00
|
|
|
out[#out+1] = ('%14.6f ms - %s'):format((vim.uv.hrtime() - ts) / 1000000, name)
|
2023-04-27 10:25:08 -07:00
|
|
|
end
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
for _, line in ipairs(exec_lua([[return out]])) do
|
|
|
|
print(line)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('nvim_create_autocmd, nvim_del_autocmd (same pattern)', function()
|
2023-12-04 15:32:39 -07:00
|
|
|
exec_lua(
|
|
|
|
[[
|
2023-04-27 10:25:08 -07:00
|
|
|
local N = ...
|
|
|
|
local ids = {}
|
|
|
|
|
|
|
|
start()
|
|
|
|
for i = 1, N do
|
|
|
|
ids[i] = vim.api.nvim_create_autocmd('User', {
|
|
|
|
pattern = 'Benchmark',
|
|
|
|
command = 'eval 0', -- noop
|
|
|
|
})
|
|
|
|
end
|
|
|
|
stop('nvim_create_autocmd')
|
|
|
|
|
|
|
|
start()
|
|
|
|
for i = 1, N do
|
|
|
|
vim.api.nvim_del_autocmd(ids[i])
|
|
|
|
end
|
|
|
|
stop('nvim_del_autocmd')
|
2023-12-04 15:32:39 -07:00
|
|
|
]],
|
|
|
|
N
|
|
|
|
)
|
2023-04-27 10:25:08 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('nvim_create_autocmd, nvim_del_autocmd (unique patterns)', function()
|
2023-12-04 15:32:39 -07:00
|
|
|
exec_lua(
|
|
|
|
[[
|
2023-04-27 10:25:08 -07:00
|
|
|
local N = ...
|
|
|
|
local ids = {}
|
|
|
|
|
|
|
|
start()
|
|
|
|
for i = 1, N do
|
|
|
|
ids[i] = vim.api.nvim_create_autocmd('User', {
|
|
|
|
pattern = 'Benchmark' .. i,
|
|
|
|
command = 'eval 0', -- noop
|
|
|
|
})
|
|
|
|
end
|
|
|
|
stop('nvim_create_autocmd')
|
|
|
|
|
|
|
|
start()
|
|
|
|
for i = 1, N do
|
|
|
|
vim.api.nvim_del_autocmd(ids[i])
|
|
|
|
end
|
|
|
|
stop('nvim_del_autocmd')
|
2023-12-04 15:32:39 -07:00
|
|
|
]],
|
|
|
|
N
|
|
|
|
)
|
2023-04-27 10:25:08 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('nvim_create_autocmd + nvim_del_autocmd', function()
|
2023-12-04 15:32:39 -07:00
|
|
|
exec_lua(
|
|
|
|
[[
|
2023-04-27 10:25:08 -07:00
|
|
|
local N = ...
|
|
|
|
|
|
|
|
start()
|
|
|
|
for _ = 1, N do
|
|
|
|
local id = vim.api.nvim_create_autocmd('User', {
|
|
|
|
pattern = 'Benchmark',
|
|
|
|
command = 'eval 0', -- noop
|
|
|
|
})
|
|
|
|
vim.api.nvim_del_autocmd(id)
|
|
|
|
end
|
|
|
|
stop('nvim_create_autocmd + nvim_del_autocmd')
|
2023-12-04 15:32:39 -07:00
|
|
|
]],
|
|
|
|
N
|
|
|
|
)
|
2023-04-27 10:25:08 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('nvim_exec_autocmds (same pattern)', function()
|
2023-12-04 15:32:39 -07:00
|
|
|
exec_lua(
|
|
|
|
[[
|
2023-04-27 10:25:08 -07:00
|
|
|
local N = ...
|
|
|
|
|
|
|
|
for i = 1, N do
|
|
|
|
vim.api.nvim_create_autocmd('User', {
|
|
|
|
pattern = 'Benchmark',
|
|
|
|
command = 'eval 0', -- noop
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
start()
|
|
|
|
vim.api.nvim_exec_autocmds('User', { pattern = 'Benchmark', modeline = false })
|
|
|
|
stop('nvim_exec_autocmds')
|
2023-12-04 15:32:39 -07:00
|
|
|
]],
|
|
|
|
N
|
|
|
|
)
|
2023-04-27 10:25:08 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('nvim_del_augroup_by_id', function()
|
2023-12-04 15:32:39 -07:00
|
|
|
exec_lua(
|
|
|
|
[[
|
2023-04-27 10:25:08 -07:00
|
|
|
local N = ...
|
|
|
|
local group = vim.api.nvim_create_augroup('Benchmark', {})
|
|
|
|
|
|
|
|
for i = 1, N do
|
|
|
|
vim.api.nvim_create_autocmd('User', {
|
|
|
|
pattern = 'Benchmark',
|
|
|
|
command = 'eval 0', -- noop
|
|
|
|
group = group,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
start()
|
|
|
|
vim.api.nvim_del_augroup_by_id(group)
|
|
|
|
stop('nvim_del_augroup_by_id')
|
2023-12-04 15:32:39 -07:00
|
|
|
]],
|
|
|
|
N
|
|
|
|
)
|
2023-04-27 10:25:08 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('nvim_del_augroup_by_name', function()
|
2023-12-04 15:32:39 -07:00
|
|
|
exec_lua(
|
|
|
|
[[
|
2023-04-27 10:25:08 -07:00
|
|
|
local N = ...
|
|
|
|
local group = vim.api.nvim_create_augroup('Benchmark', {})
|
|
|
|
|
|
|
|
for i = 1, N do
|
|
|
|
vim.api.nvim_create_autocmd('User', {
|
|
|
|
pattern = 'Benchmark',
|
|
|
|
command = 'eval 0', -- noop
|
|
|
|
group = group,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
start()
|
|
|
|
vim.api.nvim_del_augroup_by_name('Benchmark')
|
|
|
|
stop('nvim_del_augroup_by_id')
|
2023-12-04 15:32:39 -07:00
|
|
|
]],
|
|
|
|
N
|
|
|
|
)
|
2023-04-27 10:25:08 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it(':autocmd, :autocmd! (same pattern)', function()
|
2023-12-04 15:32:39 -07:00
|
|
|
exec_lua(
|
|
|
|
[[
|
2023-04-27 10:25:08 -07:00
|
|
|
local N = ...
|
|
|
|
|
|
|
|
start()
|
|
|
|
for i = 1, N do
|
|
|
|
vim.cmd('autocmd User Benchmark eval 0')
|
|
|
|
end
|
|
|
|
stop(':autocmd')
|
|
|
|
|
|
|
|
start()
|
|
|
|
vim.cmd('autocmd! User Benchmark')
|
|
|
|
stop(':autocmd!')
|
2023-12-04 15:32:39 -07:00
|
|
|
]],
|
|
|
|
N
|
|
|
|
)
|
2023-04-27 10:25:08 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it(':autocmd, :autocmd! (unique patterns)', function()
|
2023-12-04 15:32:39 -07:00
|
|
|
exec_lua(
|
|
|
|
[[
|
2023-04-27 10:25:08 -07:00
|
|
|
local N = ...
|
|
|
|
|
|
|
|
start()
|
|
|
|
for i = 1, N do
|
|
|
|
vim.cmd(('autocmd User Benchmark%d eval 0'):format(i))
|
|
|
|
end
|
|
|
|
stop(':autocmd')
|
|
|
|
|
|
|
|
start()
|
|
|
|
vim.cmd('autocmd! User')
|
|
|
|
stop(':autocmd!')
|
2023-12-04 15:32:39 -07:00
|
|
|
]],
|
|
|
|
N
|
|
|
|
)
|
2023-04-27 10:25:08 -07:00
|
|
|
end)
|
|
|
|
end)
|