Skip to content
This repository was archived by the owner on Apr 29, 2020. It is now read-only.

Commit c574f45

Browse files
committed
test: adds benchmark test
Because it's useful to have this somewhere. Skipped because we can use this to do adhoc testing and don't want it to run as part of CI. It uses 'realistic' data sizes, so 64k incoming chunks and a 500MB file size. It passes zeroed buffers as using crypto to generate random bytes was a bottleneck and didn't seem to add much to the test. It runs the test 10 times then prints out the timing data collected while importing the file which you can then use to create graphs in Google Docs or whatever.
1 parent 69504ea commit c574f45

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"ipfs-unixfs-exporter": "~0.35.4",
4545
"ipld": "~0.20.2",
4646
"multihashes": "~0.4.14",
47+
"pull-buffer-stream": "^1.0.1",
4748
"pull-generate": "^2.2.0",
4849
"pull-traverse": "^1.0.3",
4950
"sinon": "^7.1.0"

test/benchmark.spec.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
/*
4+
try {
5+
require('@achingbrain/appmetrics-dash').monitor()
6+
} catch (error) {
7+
console.error(`💥 Enabling profiling failed`, error) // eslint-disable-line no-console
8+
}
9+
*/
10+
const importer = require('../src')
11+
12+
const chai = require('chai')
13+
chai.use(require('dirty-chai'))
14+
const expect = chai.expect
15+
const pull = require('pull-stream/pull')
16+
const values = require('pull-stream/sources/values')
17+
const onEnd = require('pull-stream/sinks/on-end')
18+
const IPLD = require('ipld')
19+
const bufferStream = require('pull-buffer-stream')
20+
21+
const REPEATS = 10
22+
const FILE_SIZE = Math.pow(2, 20) * 500 // 500MB
23+
const CHUNK_SIZE = 65536
24+
25+
describe.skip('benchmark', function () {
26+
this.timeout(30 * 1000)
27+
28+
let ipld
29+
30+
before((done) => {
31+
IPLD.inMemory((err, resolver) => {
32+
expect(err).to.not.exist()
33+
34+
ipld = resolver
35+
36+
done()
37+
})
38+
})
39+
40+
const times = []
41+
42+
after(() => {
43+
console.info(`Percent\tms`)
44+
times.forEach((time, index) => {
45+
console.info(`${index}\t${parseInt(time/REPEATS)}`)
46+
})
47+
})
48+
49+
for (let i = 0; i < REPEATS; i++) {
50+
it(`run ${i}`, (done) => {
51+
this.timeout(0)
52+
53+
const size = FILE_SIZE
54+
let read = 0
55+
let lastDate = Date.now()
56+
let lastPercent = 0
57+
58+
const options = {
59+
progress: (prog) => {
60+
read += prog
61+
62+
const percent = parseInt((read / size) * 100)
63+
64+
if (percent > lastPercent) {
65+
times[percent] = (times[percent] || 0) + (Date.now() - lastDate)
66+
67+
lastDate = Date.now()
68+
lastPercent = percent
69+
}
70+
}
71+
}
72+
73+
const buf = Buffer.alloc(CHUNK_SIZE).fill(0)
74+
75+
pull(
76+
values([{
77+
path: '200Bytes.txt',
78+
content: bufferStream(size, {
79+
chunkSize: CHUNK_SIZE,
80+
generator: (num, cb) => {
81+
cb(null, buf)
82+
}
83+
})
84+
}]),
85+
importer(ipld, options),
86+
onEnd((err) => {
87+
expect(err).to.not.exist()
88+
done()
89+
})
90+
)
91+
})
92+
}
93+
})

0 commit comments

Comments
 (0)