Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: add initial blob benchmark #44990

Merged
merged 3 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
30 changes: 30 additions & 0 deletions benchmark/blob/blob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';
const common = require('../common.js');
const { Blob } = require('buffer');

const bench = common.createBenchmark(main, {
bytes: [0, 128, 512, 1024],
anonrig marked this conversation as resolved.
Show resolved Hide resolved
n: [1e6],
operation: ['text', 'arrayBuffer']
});

async function run(n, bytes, operation) {
const buff = Buffer.allocUnsafe(bytes);
const source = new Blob(buff);
bench.start();
for (let i = 0; i < n; i++) {
switch (operation) {
case 'text':
await source.text();
break;
case 'arrayBuffer':
await source.arrayBuffer();
break;
}
}
bench.end(n);
}

function main(conf) {
run(conf.n, conf.bytes, conf.operation).catch(console.log);
}
7 changes: 7 additions & 0 deletions test/benchmark/test-benchmark-blob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

require('../common');

const runBenchmark = require('../common/benchmark');

runBenchmark('blob', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });