bench_regexp_spec.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. -- Test for benchmarking the RE engine.
  2. local helpers = require('test.functional.helpers')(after_each)
  3. local insert, source = helpers.insert, helpers.source
  4. local clear, command = helpers.clear, helpers.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 =
  11. [[call Measure(%d, ']] .. sample_file .. [[', '\s\+\%%#\@<!$', '+5')]]
  12. local measure_script = [[
  13. func Measure(re, file, pattern, arg)
  14. let sstart = reltime()
  15. execute 'set re=' .. a:re
  16. execute 'split' a:arg a:file
  17. call search(a:pattern, '', '', 10000)
  18. quit!
  19. $put =printf('file: %s, re: %d, time: %s', a:file, a:re, reltimestr(reltime(sstart)))
  20. endfunc]]
  21. describe('regexp search', function()
  22. -- The test cases rely on a temporary result file, which we prepare and write
  23. -- to disk.
  24. setup(function()
  25. clear()
  26. source(measure_script)
  27. insert('" Benchmark_results:')
  28. command('write! ' .. result_file)
  29. end)
  30. -- At the end of the test run we just print the contents of the result file
  31. -- for human inspection and promptly delete the file.
  32. teardown(function()
  33. print ''
  34. for line in io.lines(result_file) do
  35. print(line)
  36. end
  37. os.remove(result_file)
  38. end)
  39. it('is working with regexpengine=0', function()
  40. local regexpengine = 0
  41. command(string.format(measure_cmd, regexpengine))
  42. command('write')
  43. end)
  44. it('is working with regexpengine=1', function()
  45. local regexpengine = 1
  46. command(string.format(measure_cmd, regexpengine))
  47. command('write')
  48. end)
  49. it('is working with regexpengine=2', function()
  50. local regexpengine = 2
  51. command(string.format(measure_cmd, regexpengine))
  52. command('write')
  53. end)
  54. end)