benchmark: add variety of inputs to text-encoder

PR-URL: https://github.com/nodejs/node/pull/45787
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
This commit is contained in:
Yagiz Nizipli 2022-12-10 09:45:22 -05:00 committed by GitHub
parent 894aff75be
commit b06fd8cd45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,17 +2,30 @@
const common = require('../common.js');
const BASE = 'string\ud801';
const bench = common.createBenchmark(main, {
len: [256, 1024, 1024 * 32],
len: [16, 32, 256, 1024, 1024 * 32],
n: [1e4],
type: ['one-byte-string', 'two-byte-string', 'ascii'],
op: ['encode', 'encodeInto']
});
function main({ n, op, len }) {
function main({ n, op, len, type }) {
const encoder = new TextEncoder();
const input = BASE.repeat(len);
let base = '';
switch (type) {
case 'ascii':
base = 'a';
break;
case 'one-byte-string':
base = '\xff';
break;
case 'two-byte-string':
base = 'ğ';
break;
}
const input = base.repeat(len);
const subarray = new Uint8Array(len);
bench.start();