Skip to content

Commit

Permalink
benchmark: fix text-decoder benchmark
Browse files Browse the repository at this point in the history
PR-URL: #45363
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
anonrig authored and danielleadams committed Jan 4, 2023
1 parent 9b231be commit 3857f39
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions benchmark/util/text-decoder.js
@@ -0,0 +1,21 @@
'use strict';

const common = require('../common.js');

const bench = common.createBenchmark(main, {
encoding: ['utf-8', 'latin1', 'iso-8859-3'],
ignoreBOM: [0, 1],
len: [256, 1024 * 16, 1024 * 512],
n: [1e6]
});

function main({ encoding, len, n, ignoreBOM }) {
const buf = Buffer.allocUnsafe(len);
const decoder = new TextDecoder(encoding, { ignoreBOM });

bench.start();
for (let i = 0; i < n; i++) {
decoder.decode(buf);
}
bench.end(n);
}

0 comments on commit 3857f39

Please sign in to comment.