-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathput-get.js
49 lines (38 loc) · 1.1 KB
/
put-get.js
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
/* eslint max-nested-callbacks: ["error", 5] */
/* eslint-disable no-console */
import assert from 'assert'
import Benchmark from 'benchmark'
import all from 'it-all'
import drain from 'it-drain'
import { makeBlocks } from '../test/utils/make-blocks.js'
import { genBitswapNetwork } from '../test/utils/mocks.js'
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 makeBlocks(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
})
})()