From 2b7784f8983187a9aa0210f93311f0e1ab1578e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Fri, 13 Dec 2024 20:39:25 +0100 Subject: [PATCH] test: added a fold timing measure refer: #3054 --- test/perf-folding/measure.vim | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 test/perf-folding/measure.vim diff --git a/test/perf-folding/measure.vim b/test/perf-folding/measure.vim new file mode 100644 index 0000000000..fed695dacb --- /dev/null +++ b/test/perf-folding/measure.vim @@ -0,0 +1,48 @@ +set nocompatible +set runtimepath^=../.. +filetype plugin on + +nnoremap q :qall! + +function! Report() + let l:sum = 0 + let l:max = 0 + for [l:key, l:value] in items(g:time_per_lnum) + let l:sum += l:value + if l:value > l:max + let l:max = l:value + endif + endfor + + echo 'Number: ' .. len(g:time_per_lnum) + echo 'Sum: ' .. l:sum + echo 'Max: ' .. l:max + echo 'Avg: ' .. l:sum/len(g:time_per_lnum) + echo 'Repeats: ' .. len(g:repeats_per_lnum) +endfunction + +let g:time_per_lnum = {} +let g:repeats_per_lnum = {} +function! FoldLevel() + let start_time = reltime() + let l:res = vimtex#fold#level(v:lnum) + let elapsed_time = reltimefloat(reltime(start_time)) + if has_key(g:time_per_lnum, v:lnum) + let g:repeats_per_lnum[v:lnum] = get(g:repeats_per_lnum, v:lnum, 0) + 1 + endif + + let g:time_per_lnum[v:lnum] = elapsed_time + + return l:res +endfunction + +let g:vimtex_cache_root = "." +let g:vimtex_cache_persistent = v:false + +setlocal foldmethod=expr +setlocal foldexpr=FoldLevel() +setlocal foldtext=vimtex#fold#text() + +nnoremap tt :call Report() + +silent edit ../example-startup-timing/thesis.tex