Skip to content

Commit 6adaf23

Browse files
authored
benchmark: add blob benchmark
PR-URL: #44990 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent b65db88 commit 6adaf23

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

benchmark/blob/blob.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const { Blob } = require('buffer');
4+
5+
const bench = common.createBenchmark(main, {
6+
bytes: [128, 1024, 1024 ** 2],
7+
n: [1e6],
8+
operation: ['text', 'arrayBuffer']
9+
});
10+
11+
async function run(n, bytes, operation) {
12+
const buff = Buffer.allocUnsafe(bytes);
13+
const source = new Blob(buff);
14+
bench.start();
15+
for (let i = 0; i < n; i++) {
16+
switch (operation) {
17+
case 'text':
18+
await source.text();
19+
break;
20+
case 'arrayBuffer':
21+
await source.arrayBuffer();
22+
break;
23+
}
24+
}
25+
bench.end(n);
26+
}
27+
28+
function main(conf) {
29+
run(conf.n, conf.bytes, conf.operation).catch(console.log);
30+
}

test/benchmark/test-benchmark-blob.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const runBenchmark = require('../common/benchmark');
6+
7+
runBenchmark('blob', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });

0 commit comments

Comments
 (0)