-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathput-get.js
More file actions
50 lines (39 loc) · 1.14 KB
/
put-get.js
File metadata and controls
50 lines (39 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* eslint max-nested-callbacks: ["error", 5] */
/* eslint-disable no-console */
'use strict'
const Benchmark = require('benchmark')
const assert = require('assert')
const all = require('it-all')
const drain = require('it-drain')
const makeBlock = require('../test/utils/make-block')
const genBitswapNetwork = require('../test/utils/mocks').genBitswapNetwork
const suite = new Benchmark.Suite('put-get')
const blockCounts = [1, 10, 1000]
const blockSizes = [10, 1024, 10 * 1024]
;(async function () {
const [
node
] = await genBitswapNetwork(1)
const bitswap = node.bitswap
blockCounts.forEach((n) => blockSizes.forEach((k) => {
suite.add(`put-get ${n} blocks of size ${k}`, async (defer) => {
const blocks = await makeBlock(n, k)
await drain(bitswap.putMany(blocks))
const res = await all(bitswap.getMany(blocks.map(block => block.cid)))
assert(res.length === blocks.length)
defer.resolve()
}, {
defer: true
})
}))
suite
.on('cycle', (event) => {
console.log(String(event.target))
})
.on('complete', () => {
process.exit()
})
.run({
async: true
})
})()