bench_regexp_spec.lua 1.9 KB

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