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

Commit aa86710

Browse files
authored
Merge pull request #11 from ipfs/add-benchmark-test
test: adds benchmark test
2 parents 373138c + 3576e1e commit aa86710

File tree

3 files changed

+181
-0
lines changed

3 files changed

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

test/no

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)