Skip to content

Commit b1f8aa3

Browse files
committed
benchmark: denoise TextDecoder benchmark a bit, add utf-16le/be
1 parent d2ab53d commit b1f8aa3

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

benchmark/util/text-decoder-stream.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22

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

5+
const MAX_N = 256 * 1024;
6+
const TOTAL_SIZE = 256 * 1024 * 1024;
7+
58
const bench = common.createBenchmark(main, {
69
encoding: ['utf-8', 'utf-16le'],
710
ignoreBOM: [0, 1],
811
fatal: [0, 1],
912
unicode: [0, 1],
1013
len: [256, 1024 * 16, 1024 * 128],
1114
chunks: [10],
12-
n: [1e3],
1315
type: ['SharedArrayBuffer', 'ArrayBuffer', 'Buffer'],
1416
});
1517

1618
const UNICODE_ALPHA = 'Blåbærsyltetøy';
1719
const ASCII_ALPHA = 'Blueberry jam';
1820

19-
function main({ encoding, len, unicode, chunks, n, ignoreBOM, type, fatal }) {
21+
function main({ encoding, len, unicode, chunks, ignoreBOM, type, fatal }) {
2022
const decoder = new TextDecoder(encoding, { ignoreBOM, fatal });
2123
let buf;
2224

@@ -41,6 +43,7 @@ function main({ encoding, len, unicode, chunks, n, ignoreBOM, type, fatal }) {
4143

4244
const chunk = Math.ceil(len / chunks);
4345
const max = len - chunk;
46+
const n = Math.min(MAX_N, Math.ceil(TOTAL_SIZE / len));
4447
bench.start();
4548
for (let i = 0; i < n; i++) {
4649
let pos = 0;

benchmark/util/text-decoder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const common = require('../common.js');
44

55
const bench = common.createBenchmark(main, {
6-
encoding: ['utf-8', 'windows-1252', 'iso-8859-3'],
6+
encoding: ['utf-8', 'utf-16le', 'utf-16be', 'windows-1252', 'iso-8859-3'],
77
ignoreBOM: [0, 1],
88
fatal: [0, 1],
99
len: [256, 1024 * 16, 1024 * 128],
@@ -25,7 +25,7 @@ function main({ encoding, len, n, ignoreBOM, type, fatal }) {
2525
break;
2626
}
2727
case 'Buffer': {
28-
buf = Buffer.allocUnsafe(len);
28+
buf = Buffer.alloc(len);
2929
break;
3030
}
3131
}

0 commit comments

Comments
 (0)