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

Commit 945166c

Browse files
committed
Add benchmark for very large buffers
1 parent 7fa231f commit 945166c

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const http = require('http')
2+
const fs = require('fs')
3+
const unzip = require('unzip')
4+
const { TextBuffer } = require('..')
5+
6+
const unzipper = unzip.Parse()
7+
8+
const getText = () => {
9+
return new Promise(resolve => {
10+
console.log('fetching text file...')
11+
const req = http.get({
12+
hostname: 'www.acleddata.com',
13+
port: 80,
14+
// 51 MB text file
15+
path: '/wp-content/uploads/2017/01/ACLED-Version-7-All-Africa-1997-2016_csv_dyadic-file.zip',
16+
agent: false
17+
}, res => {
18+
res
19+
.pipe(unzipper)
20+
.on('entry', entry => {
21+
let data = '';
22+
entry.on('data', chunk => data += chunk);
23+
entry.on('end', () => {
24+
resolve(data)
25+
});
26+
})
27+
})
28+
29+
req.end()
30+
})
31+
}
32+
33+
const timer = size => `Time to find "cat" in ${size} file`
34+
35+
getText().then(txt => {
36+
const buffer = new TextBuffer()
37+
38+
console.log('running findWordsWithSubsequence tests...')
39+
40+
const sizes = [['10b', 10], ['100b', 100], ['1kb', 1000], ['1MB', 1000000], ['51MB', 100000000]]
41+
42+
const test = size => {
43+
const _timer = timer(size[0])
44+
buffer.setText(txt.slice(0, size[1]))
45+
console.time(_timer)
46+
return buffer.findWordsWithSubsequence('cat', '', 100).then(sugs => {
47+
console.timeEnd(_timer)
48+
})
49+
}
50+
51+
return sizes.reduce((promise, size) => {
52+
return promise.then(() => test(size))
53+
}, Promise.resolve())
54+
}).then(() => {
55+
console.log('finished')
56+
})

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"random-seed": "^0.2.0",
4141
"stackvis": "^0.4.0",
4242
"standard": "^4.5.4",
43-
"temp": "^0.8.3"
43+
"temp": "^0.8.3",
44+
"unzip": "^0.1.11"
4445
},
4546
"standard": {
4647
"global": [

0 commit comments

Comments
 (0)