Skip to content

Commit

Permalink
feat: add benchmark command
Browse files Browse the repository at this point in the history
  • Loading branch information
windwp committed Aug 27, 2021
1 parent be5ae17 commit 504eac1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ animation.animation({
interval = 100,
})
```
## Benchmark
A command to benchmark current statuline it will render statusline 20.000 time.
`:WindLineBenchMark`

## Tabline
[view](https://github.com/windwp/windline.nvim/wiki/tabline)
Expand Down
5 changes: 4 additions & 1 deletion lua/windline/component.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

---@class Component
---@field hl_colors table
---@field text function
---@field hl function
---@field created boolean
local Comp = {}
local utils=require('windline.utils')

Expand Down
14 changes: 14 additions & 0 deletions lua/windline/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,20 @@ M.setup = function(opts)
augroup END]],
false
)
api.nvim_exec("command! -nargs=* WindLineBenchmark lua require('windline').benchmark()", false)
end

--- a benchmark current statusline. it need plenary
M.benchmark = function()
local num = 2e4
local bench = require('plenary.profile').benchmark
local statusline = ''
local time = bench(num, function()
vim.g.statusline_winid = vim.api.nvim_get_current_win()
statusline = WindLine.show(vim.api.nvim_get_current_buf(), vim.g.statusline_winid)
end)
print(statusline)
print(string.format('render %s time : %s', num, time ))
end

M.add_status = function(lines)
Expand Down
30 changes: 21 additions & 9 deletions tests/benchmark.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
local bench = require('plenary.profile').benchmark

-- local num = 10
-- test time to render status line
local num = 2e4
local item = ''
print('total time: ', bench(num, function()
vim.g.statusline_winid = vim.api.nvim_get_current_win()
item = WindLine.show(vim.api.nvim_get_current_buf(), vim.g.statusline_winid)
end))
vim.cmd([[packadd plenary.nvim]])
vim.cmd([[packadd windline.nvim]])
vim.opt.termguicolors = true

local log = require('plenary.log').new({ level = 'debug' })
require('wlsample.evil_line')

vim.cmd([[e ./tests/benchmark.lua]])
-- wait to vim enter end test
vim.defer_fn(function()
local bench = require('plenary.profile').benchmark
local statusline = ''
local time = bench(num, function()
vim.g.statusline_winid = vim.api.nvim_get_current_win()
statusline = WindLine.show(vim.api.nvim_get_current_buf(), vim.g.statusline_winid)
end)

print(vim.inspect(item))
log.info(statusline)
log.info('windline time :' .. time)
vim.cmd([[quit]])
end, 100)

0 comments on commit 504eac1

Please sign in to comment.