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 <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
  • Loading branch information
anonrig authored Dec 10, 2022
1 parent 894aff7 commit b06fd8c
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 b06fd8c

Please sign in to comment.