Skip to content

Commit 9925d20

Browse files
anonrigdanielleadams
authored andcommitted
benchmark: add variety of inputs to text-encoder
PR-URL: #45787 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
1 parent 2fbf956 commit 9925d20

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

benchmark/util/text-encoder.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,30 @@
22

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

5-
const BASE = 'string\ud801';
6-
75
const bench = common.createBenchmark(main, {
8-
len: [256, 1024, 1024 * 32],
6+
len: [16, 32, 256, 1024, 1024 * 32],
97
n: [1e4],
8+
type: ['one-byte-string', 'two-byte-string', 'ascii'],
109
op: ['encode', 'encodeInto']
1110
});
1211

13-
function main({ n, op, len }) {
12+
function main({ n, op, len, type }) {
1413
const encoder = new TextEncoder();
15-
const input = BASE.repeat(len);
14+
let base = '';
15+
16+
switch (type) {
17+
case 'ascii':
18+
base = 'a';
19+
break;
20+
case 'one-byte-string':
21+
base = '\xff';
22+
break;
23+
case 'two-byte-string':
24+
base = 'ğ';
25+
break;
26+
}
27+
28+
const input = base.repeat(len);
1629
const subarray = new Uint8Array(len);
1730

1831
bench.start();

0 commit comments

Comments
 (0)