Skip to content

Commit fbe8351

Browse files
committed
benchmark: add text-encoder benchmark
1 parent c4d75ea commit fbe8351

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

benchmark/util/text-encoder.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
5+
const BASE = 'string\ud801';
6+
7+
const bench = common.createBenchmark(main, {
8+
n: [1e4],
9+
op: ['encode', 'encodeInto']
10+
});
11+
12+
function main({ n, ignoreBOM, op }) {
13+
const encoder = new TextEncoder();
14+
const input = BASE.repeat(n);
15+
const subarray = new Uint8Array(n);
16+
17+
bench.start();
18+
for (let i = 0; i < n; i++) {
19+
switch (op) {
20+
case 'encode': {
21+
encoder.encode(input);
22+
break;
23+
}
24+
case 'encodeInto': {
25+
encoder.encodeInto(input, subarray);
26+
break;
27+
}
28+
}
29+
}
30+
bench.end(n);
31+
}

0 commit comments

Comments
 (0)