neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

bench_regexp_spec.lua (1952B)


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