benchmark: add parameters to text-decoder benchmark

PR-URL: https://github.com/nodejs/node/pull/45363
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Yagiz Nizipli 2022-11-07 09:07:09 -05:00 committed by Node.js GitHub Bot
parent e3b3c4697c
commit 86a5b71dc9

View File

@ -6,12 +6,28 @@ const bench = common.createBenchmark(main, {
encoding: ['utf-8', 'latin1', 'iso-8859-3'],
ignoreBOM: [0, 1],
len: [256, 1024 * 16, 1024 * 512],
n: [1e6]
n: [1e2],
type: ['SharedArrayBuffer', 'ArrayBuffer', 'Buffer']
});
function main({ encoding, len, n, ignoreBOM }) {
const buf = Buffer.allocUnsafe(len);
function main({ encoding, len, n, ignoreBOM, type }) {
const decoder = new TextDecoder(encoding, { ignoreBOM });
let buf;
switch (type) {
case 'SharedArrayBuffer': {
buf = new SharedArrayBuffer(len);
break;
}
case 'ArrayBuffer': {
buf = new ArrayBuffer(len);
break;
}
case 'Buffer': {
buf = Buffer.allocUnsafe(len);
break;
}
}
bench.start();
for (let i = 0; i < n; i++) {