Skip to content

Commit

Permalink
benchmark: add variety of inputs to text-encoder
Browse files Browse the repository at this point in the history
PR-URL: #45787
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Daeyeon Jeong <[email protected]>
  • Loading branch information
anonrig authored and targos committed Dec 13, 2022
1 parent e2caf7c commit 382efdf
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions benchmark/util/text-encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 382efdf

Please sign in to comment.