mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
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:
parent
894aff75be
commit
b06fd8cd45
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user