mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
8fa7d90c78
PR-URL: https://github.com/nodejs/node/pull/52548 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
31 lines
665 B
JavaScript
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);
|
|
}
|