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

test: adds benchmark test #11

Merged
merged 1 commit into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"ipfs-unixfs-exporter": "~0.35.4",
"ipld": "~0.20.2",
"multihashes": "~0.4.14",
"pull-buffer-stream": "^1.0.1",
"pull-generate": "^2.2.0",
"pull-traverse": "^1.0.3",
"sinon": "^7.1.0"
Expand Down
87 changes: 87 additions & 0 deletions test/benchmark.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* eslint-env mocha */
'use strict'

const importer = require('../src')

const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const pull = require('pull-stream/pull')
const values = require('pull-stream/sources/values')
const onEnd = require('pull-stream/sinks/on-end')
const IPLD = require('ipld')
const bufferStream = require('pull-buffer-stream')

const REPEATS = 10
const FILE_SIZE = Math.pow(2, 20) * 500 // 500MB
const CHUNK_SIZE = 65536

describe.skip('benchmark', function () {
this.timeout(30 * 1000)

let ipld

before((done) => {
IPLD.inMemory((err, resolver) => {
expect(err).to.not.exist()

ipld = resolver

done()
})
})

const times = []

after(() => {
console.info(`Percent\tms`)
times.forEach((time, index) => {
console.info(`${index}\t${parseInt(time / REPEATS)}`)
})
})

for (let i = 0; i < REPEATS; i++) {
it(`run ${i}`, (done) => { // eslint-disable-line no-loop-func
this.timeout(0)

const size = FILE_SIZE
let read = 0
let lastDate = Date.now()
let lastPercent = 0

const options = {
progress: (prog) => {
read += prog

const percent = parseInt((read / size) * 100)

if (percent > lastPercent) {
times[percent] = (times[percent] || 0) + (Date.now() - lastDate)

lastDate = Date.now()
lastPercent = percent
}
}
}

const buf = Buffer.alloc(CHUNK_SIZE).fill(0)

pull(
values([{
path: '200Bytes.txt',
content: bufferStream(size, {
chunkSize: CHUNK_SIZE,
generator: (num, cb) => {
cb(null, buf)
}
})
}]),
importer(ipld, options),
onEnd((err) => {
expect(err).to.not.exist()
done()
})
)
})
}
})
93 changes: 93 additions & 0 deletions test/no
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* eslint-env mocha */
'use strict'
/*
try {
require('@achingbrain/appmetrics-dash').monitor()
} catch (error) {
console.error(`💥 Enabling profiling failed`, error) // eslint-disable-line no-console
}
*/
const importer = require('../src')

const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const pull = require('pull-stream/pull')
const values = require('pull-stream/sources/values')
const onEnd = require('pull-stream/sinks/on-end')
const IPLD = require('ipld')
const bufferStream = require('pull-buffer-stream')

const REPEATS = 10
const FILE_SIZE = Math.pow(2, 20) * 500 // 500MB
const CHUNK_SIZE = 65536

describe.skip('benchmark', function () {
this.timeout(30 * 1000)

let ipld

before((done) => {
IPLD.inMemory((err, resolver) => {
expect(err).to.not.exist()

ipld = resolver

done()
})
})

const times = []

after(() => {
console.info(`Percent\tms`)
times.forEach((time, index) => {
console.info(`${index}\t${parseInt(time/REPEATS)}`)
})
})

for (let i = 0; i < REPEATS; i++) {
it(`run ${i}`, (done) => {
this.timeout(0)

const size = FILE_SIZE
let read = 0
let lastDate = Date.now()
let lastPercent = 0

const options = {
progress: (prog) => {
read += prog

const percent = parseInt((read / size) * 100)

if (percent > lastPercent) {
times[percent] = (times[percent] || 0) + (Date.now() - lastDate)

lastDate = Date.now()
lastPercent = percent
}
}
}

const buf = Buffer.alloc(CHUNK_SIZE).fill(0)

pull(
values([{
path: '200Bytes.txt',
content: bufferStream(size, {
chunkSize: CHUNK_SIZE,
generator: (num, cb) => {
cb(null, buf)
}
})
}]),
importer(ipld, options),
onEnd((err) => {
expect(err).to.not.exist()
done()
})
)
})
}
})