Skip to content

Commit

Permalink
chore: Add benchmark file
Browse files Browse the repository at this point in the history
  • Loading branch information
marcbachmann committed Jun 4, 2020
1 parent 45313f4 commit 2ffaffc
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
27 changes: 27 additions & 0 deletions benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const bench = require('nanobench')
const createSearch = require('./')
let count = 1000
const largeArray = []
const hashes = { 1: 'foo', 2: 'foo bar', 3: 'hello', 4: 'world', 5: 'baz qux' }
while (count--) largeArray.push(`aaaaaaaaaaaaaaaaaaa${hashes[count] || ''}`)

bench('instantiate 1000000 times', function (b) {
b.start()

for (let i = 0; i < 1000000; i++) {
createSearch(largeArray)
}

b.end()
})

const search = createSearch(largeArray)
bench('search 10000 times', function (b) {
b.start()

for (let i = 0; i < 10000; i++) {
search('foo bar baz qux')
}

b.end()
})
89 changes: 89 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"author": "Marc Bachmann <marc.brookman@gmail.com>",
"license": "MIT",
"devDependencies": {
"nanobench": "^2.1.1",
"standard": "^14.3.3"
},
"dependencies": {},
Expand Down

0 comments on commit 2ffaffc

Please sign in to comment.