We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0f3cf7e commit 26ad54cCopy full SHA for 26ad54c
benchmark/util/text-encoder.js
@@ -0,0 +1,32 @@
1
+'use strict';
2
+
3
+const common = require('../common.js');
4
5
+const BASE = 'string\ud801';
6
7
+const bench = common.createBenchmark(main, {
8
+ len: [256, 1024, 1024 * 32],
9
+ n: [1e4],
10
+ op: ['encode', 'encodeInto']
11
+});
12
13
+function main({ n, op, len }) {
14
+ const encoder = new TextEncoder();
15
+ const input = BASE.repeat(len);
16
+ const subarray = new Uint8Array(len);
17
18
+ bench.start();
19
+ switch (op) {
20
+ case 'encode': {
21
+ for (let i = 0; i < n; i++)
22
+ encoder.encode(input);
23
+ break;
24
+ }
25
+ case 'encodeInto': {
26
27
+ encoder.encodeInto(input, subarray);
28
29
30
31
+ bench.end(n);
32
+}
0 commit comments