robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
1.6 KiB60 linesraw
1local n = require('test.functional.testnvim')()
2local t = require('test.testutil')
3local describe, it = t.describe, t.it
4local clear = n.clear
5local api = n.api
6local fn = n.fn
7
8local keycodes = require('src.nvim.keycodes')
9
10describe('nvim_replace_termcodes performance', function()
11  it('200 calls with a key repeated 5000 times', function()
12    clear()
13    local stats = {}
14    local ms = 1 / 1000000
15
16    for _, keycode in ipairs(keycodes.names) do
17      local notation = ('<%s>'):format(keycode[2])
18      local str = notation:rep(5000)
19
20      local start = vim.uv.hrtime()
21      for _ = 1, 200 do
22        api.nvim_replace_termcodes(str, false, true, true)
23      end
24      local elapsed = vim.uv.hrtime() - start
25
26      table.insert(stats, elapsed)
27      io.stdout:write(('\n%-20s%14.6f ms'):format(notation, elapsed * ms))
28      io.stdout:flush()
29    end
30    io.stdout:write('\n')
31
32    t.bench_report(stats, { unit = 'ms' })
33  end)
34end)
35
36describe('keytrans() performance', function()
37  it('200 calls with a key repeated 5000 times', function()
38    clear()
39    local stats = {}
40    local ms = 1 / 1000000
41
42    for _, keycode in ipairs(keycodes.names) do
43      local notation = ('<%s>'):format(keycode[2])
44      local str = api.nvim_replace_termcodes(notation, false, true, true):rep(5000)
45
46      local start = vim.uv.hrtime()
47      for _ = 1, 200 do
48        fn.keytrans(str)
49      end
50      local elapsed = vim.uv.hrtime() - start
51
52      table.insert(stats, elapsed)
53      io.stdout:write(('\n%-20s%14.6f ms'):format(notation, elapsed * ms))
54      io.stdout:flush()
55    end
56    io.stdout:write('\n')
57
58    t.bench_report(stats, { unit = 'ms' })
59  end)
60end)