robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
2.0 KiB66 linesraw
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 = [[
18    func Measure(re, file, pattern, arg)
19      let sstart = reltime()
20
21      execute 'set re=' .. a:re
22      execute 'split' a:arg a:file
23      call search(a:pattern, '', '', 10000)
24      quit!
25
26      $put =printf('file: %s, re: %d, time: %s', a:file, a:re, reltimestr(reltime(sstart)))
27    endfunc]]
28
29describe('regexp search', function()
30  -- The test cases rely on a temporary result file, which we prepare and write
31  -- to disk.
32  setup(function()
33    clear()
34    source(measure_script)
35    insert('" Benchmark_results:')
36    command('write! ' .. result_file)
37  end)
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.
41  teardown(function()
42    print ''
43    for line in io.lines(result_file) do
44      print(line)
45    end
46    os.remove(result_file)
47  end)
48
49  it('is working with regexpengine=0', function()
50    local regexpengine = 0
51    command(string.format(measure_cmd, regexpengine))
52    command('write')
53  end)
54
55  it('is working with regexpengine=1', function()
56    local regexpengine = 1
57    command(string.format(measure_cmd, regexpengine))
58    command('write')
59  end)
60
61  it('is working with regexpengine=2', function()
62    local regexpengine = 2
63    command(string.format(measure_cmd, regexpengine))
64    command('write')
65  end)
66end)