node/benchmark/blob/blob.js
Debadree Chatterjee 8fa7d90c78
benchmark: reduce the buffer size for blob
PR-URL: https://github.com/nodejs/node/pull/52548
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2024-04-17 19:33:44 +00:00

31 lines
665 B
JavaScript

'use strict';
const common = require('../common.js');
const { Blob } = require('buffer');
const bench = common.createBenchmark(main, {
bytes: [128, 1024, 8192],
n: [1e3],
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);
}