Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Add benchmark for very large buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
leroix committed Sep 28, 2017
1 parent 7fa231f commit 945166c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
56 changes: 56 additions & 0 deletions benchmark/large-text-buffer.benchmark.js
@@ -0,0 +1,56 @@
const http = require('http')
const fs = require('fs')
const unzip = require('unzip')
const { TextBuffer } = require('..')

const unzipper = unzip.Parse()

const getText = () => {
return new Promise(resolve => {
console.log('fetching text file...')
const req = http.get({
hostname: 'www.acleddata.com',
port: 80,
// 51 MB text file
path: '/wp-content/uploads/2017/01/ACLED-Version-7-All-Africa-1997-2016_csv_dyadic-file.zip',
agent: false
}, res => {
res
.pipe(unzipper)
.on('entry', entry => {
let data = '';
entry.on('data', chunk => data += chunk);
entry.on('end', () => {
resolve(data)
});
})
})

req.end()
})
}

const timer = size => `Time to find "cat" in ${size} file`

getText().then(txt => {
const buffer = new TextBuffer()

console.log('running findWordsWithSubsequence tests...')

const sizes = [['10b', 10], ['100b', 100], ['1kb', 1000], ['1MB', 1000000], ['51MB', 100000000]]

const test = size => {
const _timer = timer(size[0])
buffer.setText(txt.slice(0, size[1]))
console.time(_timer)
return buffer.findWordsWithSubsequence('cat', '', 100).then(sugs => {
console.timeEnd(_timer)
})
}

return sizes.reduce((promise, size) => {
return promise.then(() => test(size))
}, Promise.resolve())
}).then(() => {
console.log('finished')
})
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -40,7 +40,8 @@
"random-seed": "^0.2.0",
"stackvis": "^0.4.0",
"standard": "^4.5.4",
"temp": "^0.8.3"
"temp": "^0.8.3",
"unzip": "^0.1.11"
},
"standard": {
"global": [
Expand Down

0 comments on commit 945166c

Please sign in to comment.