diff options
author | Yagiz Nizipli <yagiz@nizipli.com> | 2022-12-10 09:45:22 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-10 14:45:22 +0000 |
commit | b06fd8cd455b3bb6936b7dc238a132430df768da (patch) | |
tree | 34a39ce4f75c0a191947a53e8948f4b7cc1bbd39 /benchmark | |
parent | 894aff75be5cc5e0f4d151038913ce83d39643e7 (diff) | |
download | node-new-b06fd8cd455b3bb6936b7dc238a132430df768da.tar.gz |
benchmark: add variety of inputs to text-encoder
PR-URL: https://github.com/nodejs/node/pull/45787
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/util/text-encoder.js | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/benchmark/util/text-encoder.js b/benchmark/util/text-encoder.js index ca3cb82777..707f76df11 100644 --- a/benchmark/util/text-encoder.js +++ b/benchmark/util/text-encoder.js @@ -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(); |