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