From 194fc113acc9b879b72d5a2f2133a3d898db5cea Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Tue, 3 Sep 2024 13:34:14 -0300 Subject: [PATCH] benchmark: add buffer.isAscii benchmark PR-URL: https://github.com/nodejs/node/pull/54740 Reviewed-By: Rich Trott Reviewed-By: Antoine du Hamel --- benchmark/buffers/buffer-isascii.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 benchmark/buffers/buffer-isascii.js diff --git a/benchmark/buffers/buffer-isascii.js b/benchmark/buffers/buffer-isascii.js new file mode 100644 index 00000000000000..d118049fa5ea6b --- /dev/null +++ b/benchmark/buffers/buffer-isascii.js @@ -0,0 +1,23 @@ +'use strict'; + +const common = require('../common.js'); +const buffer = require('node:buffer'); +const assert = require('node:assert'); + +const bench = common.createBenchmark(main, { + n: [2e7], + length: ['short', 'long'], + input: ['hello world'], +}); + + +function main({ n, input }) { + const normalizedInput = input === 'short' ? input : input.repeat(200); + const encoder = new TextEncoder(); + const buff = encoder.encode(normalizedInput); + bench.start(); + for (let i = 0; i < n; ++i) { + assert.ok(buffer.isAscii(buff)); + } + bench.end(n); +}