aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2025-03-08 06:04:16 +0800
committerGitHub <noreply@github.com>2025-03-08 06:04:16 +0800
commit246b1e9fb39978d815d86a3810f712b72f8737aa (patch)
tree5a0e5a22c30d7c003114bd66489b8f75c62125e4 /test
parent3d49c55d3c33a243f4236cf57b179608c288b145 (diff)
parent12d4caa9d3e4224b7c2922f112955100649d6069 (diff)
downloadrneovim-246b1e9fb39978d815d86a3810f712b72f8737aa.tar.gz
rneovim-246b1e9fb39978d815d86a3810f712b72f8737aa.tar.bz2
rneovim-246b1e9fb39978d815d86a3810f712b72f8737aa.zip
Merge pull request #32768 from zeertzjq/vim-9.1.1179
perf(keycodes): use hashy for string lookup
Diffstat (limited to 'test')
-rw-r--r--test/benchmark/keycodes_spec.lua84
1 files changed, 84 insertions, 0 deletions
diff --git a/test/benchmark/keycodes_spec.lua b/test/benchmark/keycodes_spec.lua
new file mode 100644
index 0000000000..443df2a6fb
--- /dev/null
+++ b/test/benchmark/keycodes_spec.lua
@@ -0,0 +1,84 @@
+local n = require('test.functional.testnvim')()
+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 sum = 0
+ 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)
+ sum = sum + elapsed
+ io.stdout:write(('\n%-20s%14.6f ms'):format(notation, elapsed * ms))
+ io.stdout:flush()
+ end
+ io.stdout:write('\n')
+
+ table.sort(stats)
+ print(('%18s'):rep(6):format('avg', 'min', '25%', 'median', '75%', 'max'))
+ print(
+ (' %14.6f ms'):rep(6):format(
+ sum / #stats * ms,
+ stats[1] * ms,
+ stats[1 + math.floor(#stats * 0.25)] * ms,
+ stats[1 + math.floor(#stats * 0.5)] * ms,
+ stats[1 + math.floor(#stats * 0.75)] * ms,
+ stats[#stats] * ms
+ )
+ )
+ end)
+end)
+
+describe('keytrans() performance', function()
+ it('200 calls with a key repeated 5000 times', function()
+ clear()
+ local stats = {}
+ local sum = 0
+ 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)
+ sum = sum + elapsed
+ io.stdout:write(('\n%-20s%14.6f ms'):format(notation, elapsed * ms))
+ io.stdout:flush()
+ end
+ io.stdout:write('\n')
+
+ table.sort(stats)
+ print((' %17s'):rep(6):format('avg', 'min', '25%', 'median', '75%', 'max'))
+ print(
+ (' %14.6f ms'):rep(6):format(
+ sum / #stats * ms,
+ stats[1] * ms,
+ stats[1 + math.floor(#stats * 0.25)] * ms,
+ stats[1 + math.floor(#stats * 0.5)] * ms,
+ stats[1 + math.floor(#stats * 0.75)] * ms,
+ stats[#stats] * ms
+ )
+ )
+ end)
+end)