load.vim 723 B

123456789101112131415161718192021222324252627282930313233
  1. " Also used by: test/functional/testnvim.lua
  2. function! s:load_factor() abort
  3. let timeout = 200
  4. let times = []
  5. for _ in range(5)
  6. let g:val = 0
  7. let start = reltime()
  8. call timer_start(timeout, {-> nvim_set_var('val', 1)})
  9. while 1
  10. sleep 10m
  11. if g:val == 1
  12. let g:waited_in_ms = float2nr(reltimefloat(reltime(start)) * 1000)
  13. break
  14. endif
  15. endwhile
  16. call insert(times, g:waited_in_ms, 0)
  17. endfor
  18. let longest = max(times)
  19. let factor = (longest + 50.0) / timeout
  20. return factor
  21. endfunction
  22. " Compute load factor only once.
  23. let g:test_load_factor = s:load_factor()
  24. function! LoadAdjust(num) abort
  25. return float2nr(ceil(a:num * g:test_load_factor))
  26. endfunction