From 382efdf460521a439a5c49adb1cdc6121bfe491a Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Sat, 10 Dec 2022 09:45:22 -0500 Subject: [PATCH] benchmark: add variety of inputs to text-encoder PR-URL: https://github.com/nodejs/node/pull/45787 Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Daeyeon Jeong --- benchmark/util/text-encoder.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/benchmark/util/text-encoder.js b/benchmark/util/text-encoder.js index ca3cb827779be3..707f76df11dc89 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();