2022-11-04 21:26:17 -07:00
|
|
|
-- Test for benchmarking the RE engine.
|
2015-03-28 14:28:37 -07:00
|
|
|
|
2017-04-10 12:54:19 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2015-11-17 07:52:59 -07:00
|
|
|
local insert, source = helpers.insert, helpers.source
|
2017-04-10 12:54:19 -07:00
|
|
|
local clear, command = helpers.clear, helpers.command
|
2015-03-28 14:28:37 -07:00
|
|
|
|
|
|
|
-- Temporary file for gathering benchmarking results for each regexp engine.
|
|
|
|
local result_file = 'benchmark.out'
|
|
|
|
-- Fixture containing an HTML fragment that can make a search appear to freeze.
|
2022-11-04 04:31:58 -07:00
|
|
|
local sample_file = 'src/nvim/testdir/samples/re.freeze.txt'
|
2015-03-28 14:28:37 -07:00
|
|
|
|
|
|
|
-- Vim script code that does both the work and the benchmarking of that work.
|
|
|
|
local measure_cmd =
|
|
|
|
[[call Measure(%d, ']] .. sample_file .. [[', '\s\+\%%#\@<!$', '+5')]]
|
|
|
|
local measure_script = [[
|
2022-11-04 21:26:17 -07:00
|
|
|
func Measure(re, file, pattern, arg)
|
|
|
|
let sstart = reltime()
|
2016-11-16 16:33:45 -07:00
|
|
|
|
2022-11-04 21:26:17 -07:00
|
|
|
execute 'set re=' .. a:re
|
2015-03-28 14:28:37 -07:00
|
|
|
execute 'split' a:arg a:file
|
|
|
|
call search(a:pattern, '', '', 10000)
|
2022-11-04 21:26:17 -07:00
|
|
|
quit!
|
2016-11-16 16:33:45 -07:00
|
|
|
|
2015-03-28 14:28:37 -07:00
|
|
|
$put =printf('file: %s, re: %d, time: %s', a:file, a:re, reltimestr(reltime(sstart)))
|
|
|
|
endfunc]]
|
|
|
|
|
|
|
|
describe('regexp search', function()
|
2016-04-19 16:24:03 -07:00
|
|
|
-- The test cases rely on a temporary result file, which we prepare and write
|
|
|
|
-- to disk.
|
2015-03-28 14:28:37 -07:00
|
|
|
setup(function()
|
|
|
|
clear()
|
|
|
|
source(measure_script)
|
|
|
|
insert('" Benchmark_results:')
|
2017-04-10 12:54:19 -07:00
|
|
|
command('write! ' .. result_file)
|
2015-03-28 14:28:37 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
-- At the end of the test run we just print the contents of the result file
|
|
|
|
-- for human inspection and promptly delete the file.
|
|
|
|
teardown(function()
|
|
|
|
print ''
|
|
|
|
for line in io.lines(result_file) do
|
|
|
|
print(line)
|
|
|
|
end
|
|
|
|
os.remove(result_file)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('is working with regexpengine=0', function()
|
|
|
|
local regexpengine = 0
|
2017-04-10 12:54:19 -07:00
|
|
|
command(string.format(measure_cmd, regexpengine))
|
|
|
|
command('write')
|
2015-03-28 14:28:37 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('is working with regexpengine=1', function()
|
|
|
|
local regexpengine = 1
|
2017-04-10 12:54:19 -07:00
|
|
|
command(string.format(measure_cmd, regexpengine))
|
|
|
|
command('write')
|
2015-03-28 14:28:37 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('is working with regexpengine=2', function()
|
|
|
|
local regexpengine = 2
|
2017-04-10 12:54:19 -07:00
|
|
|
command(string.format(measure_cmd, regexpengine))
|
|
|
|
command('write')
|
2015-03-28 14:28:37 -07:00
|
|
|
end)
|
|
|
|
end)
|