Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYagiz Nizipli <yagiz@nizipli.com>2022-11-13 22:41:10 +0300
committerYagiz Nizipli <yagiz@nizipli.com>2022-11-13 22:52:07 +0300
commit8f787c6cd5cb51371fe4d542f8d0c874c160e188 (patch)
treed5a41d686baecbbfc9a2ee4e6aa53d9a35b9656f
parentc4d75ea104e0e9a9f9180d6a2750886dc28a1012 (diff)
benchmark: add text-encoder benchmarkbenchmark/text-encoder
-rw-r--r--benchmark/util/text-encoder.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/benchmark/util/text-encoder.js b/benchmark/util/text-encoder.js
new file mode 100644
index 00000000000..28422fe39d8
--- /dev/null
+++ b/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, 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);
+}