-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathlocal-add.js
44 lines (41 loc) · 1.51 KB
/
local-add.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
'use strict'
const { file } = require('./lib/fixtures')
const run = require('./lib/runner')
const { build } = require('./schema/results')
const fs = require('fs')
const { description, strategy } = require('./config').parseParams()
/**
* Add file benchmark using IPFS api add.
* js0 -> js0 - A local test from one JS IPFS node to the same nod
* @async
* @function unixFsAdd
* @param {array} peerArray - An array of IPFS peers used during the test.
* @param {string} name - Name of the test used as sending results to the file with same name and data point in dashboard.
* @param {boolean} warmup - Not implemented.
* @param {string} fileSet - Describes file or list of files used for the test.
* @param {string} version - Version of IPFS used in benchmark.
* @return {Promise<Object>} The data from the benchamrk
*/
async function unixFsAdd (peerArray, name, warmup, fileSet, version) {
const filePath = await file(fileSet)
const fileStream = fs.createReadStream(filePath)
console.log(` Adding files using strategy ${strategy}`)
const start = process.hrtime()
const peer = peerArray[0]
// output file and dashboard name will match strategy. default is balanced
await peer.add(fileStream, { strategy: strategy })
const end = process.hrtime(start)
return build({
name: name,
warmup: warmup,
file: filePath,
meta: { version: version },
description: `Add file ${description} js0 -> js0`,
file_set: fileSet,
duration: {
s: end[0],
ms: end[1] / 1000000
}
})
}
run(unixFsAdd)