Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: add variety of inputs to text-encoder #45787

Merged
merged 2 commits into from Dec 10, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 18 additions & 5 deletions benchmark/util/text-encoder.js
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: [0, 256, 1024, 1024 * 32],
anonrig marked this conversation as resolved.
Show resolved Hide resolved
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