perf_helper.js 615 B

1234567891011121314151617181920212223242526
  1. var lunr = require('../lunr.js'),
  2. Benchmark = require('benchmark'),
  3. wordList = require('word-list'),
  4. fs = require('fs')
  5. var suite = function (name, fn) {
  6. var s = new Benchmark.Suite(name, {
  7. onStart: function (e) { console.log(e.currentTarget.name) },
  8. onCycle: function (e) { console.log(" " + String(e.target)) },
  9. onError: function (e) { console.error(e.target.error) }
  10. })
  11. fn.call(s, s)
  12. s.run()
  13. }
  14. var words = fs.readFileSync(wordList, 'utf-8')
  15. .split('\n')
  16. .slice(0, 1000)
  17. .sort()
  18. global.lunr = lunr
  19. global.Benchmark = Benchmark
  20. global.suite = suite
  21. global.words = words