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 and danielleadams committed Jan 3, 2023
1 parent 2fbf956 commit 9925d20
Showing 1 changed file with 18 additions and 5 deletions.
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: [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

1 comment on commit 9925d20

@Dreaky
Copy link

@Dreaky Dreaky commented on 9925d20 Jan 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi guys, I found this change after my unit test failed on basic DateTime and Timestamp formatting:

eg. AssertionError: expected '9/13/1987, 2:00:00\u202fAM' to be '9/13/1987, 2:00:00 AM' // Object.is equality

  • Expected"9/13/1987, 2:00:00 AM"
  • Received"9/13/1987, 2:00:00 AM"

did you see some similarities with this commit like me?

Please sign in to comment.