Skip to content

Commit

Permalink
benchmark: add text-encoder benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Nov 13, 2022
1 parent c4d75ea commit fbe8351
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions benchmark/util/text-encoder.js
@@ -0,0 +1,31 @@
'use strict';

const common = require('../common.js');

const BASE = 'string\ud801';

const bench = common.createBenchmark(main, {
n: [1e4],
op: ['encode', 'encodeInto']
});

function main({ n, ignoreBOM, op }) {
const encoder = new TextEncoder();
const input = BASE.repeat(n);
const subarray = new Uint8Array(n);

bench.start();
for (let i = 0; i < n; i++) {
switch (op) {
case 'encode': {
encoder.encode(input);
break;
}
case 'encodeInto': {
encoder.encodeInto(input, subarray);
break;
}
}
}
bench.end(n);
}

0 comments on commit fbe8351

Please sign in to comment.