robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1-- Test for benchmarking the RE engine. 2 3local n =require ( 'test.functional.testnvim' )() 4local t =require ( 'test.testutil' ) 5 6local describe , it , setup , teardown =t . describe , t . it , t . setup , t . teardown 7local insert , source =n . insert , n . source 8local clear , command =n . clear , n . command 9 10-- Temporary file for gathering benchmarking results for each regexp engine. 11local result_file ='benchmark.out' 12-- Fixture containing an HTML fragment that can make a search appear to freeze. 13local sample_file ='test/old/testdir/samples/re.freeze.txt' 14 15-- Vim script code that does both the work and the benchmarking of that work. 16local measure_cmd =[[call Measure(%d, ']] .. sample_file .. [[', '\s\+\%%#\@<!$', '+5')]] 17local measure_script =[[ 18func Measure(re, file, pattern, arg) 19let sstart = reltime() 20 21execute 'set re=' .. a:re 22execute 'split' a:arg a:file 23call search(a:pattern, '', '', 10000) 24quit! 25 26$put =printf('file: %s, re: %d, time: %s', a:file, a:re, reltimestr(reltime(sstart))) 27endfunc]] 28 29describe ( 'regexp search' , function () 30-- The test cases rely on a temporary result file, which we prepare and write 31-- to disk. 32setup ( function () 33clear () 34source ( measure_script ) 35insert ( '" Benchmark_results:' ) 36command ( 'write! ' .. result_file ) 37end ) 38 39-- At the end of the test run we just print the contents of the result file 40-- for human inspection and promptly delete the file. 41teardown ( function () 42'' 43for line in io . lines ( result_file ) do 44( line ) 45end 46os . remove ( result_file ) 47end ) 48 49it ( 'is working with regexpengine=0' , function () 50local regexpengine =0 51command ( string . format ( measure_cmd , regexpengine )) 52command ( 'write' ) 53end ) 54 55it ( 'is working with regexpengine=1' , function () 56local regexpengine =1 57command ( string . format ( measure_cmd , regexpengine )) 58command ( 'write' ) 59end ) 60 61it ( 'is working with regexpengine=2' , function () 62local regexpengine =2 63command ( string . format ( measure_cmd , regexpengine )) 64command ( 'write' ) 65end ) 66end )