Skip to content

Commit

Permalink
benchmark: add parameters to text-decoder benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Nov 7, 2022
1 parent f078c4a commit 79e26b5
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions benchmark/util/text-decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down

0 comments on commit 79e26b5

Please sign in to comment.