From 5f9d07f247d4b0f8b035753bc2bfe76a2f49eaf4 Mon Sep 17 00:00:00 2001 From: SeokhunEom Date: Mon, 6 Oct 2025 19:17:48 +0900 Subject: [PATCH 1/2] benchmark: allow boolean option values Change createBenchmark to also accept booleans. Update writing-and-running-benchmarks.md and format the md. --- benchmark/common.js | 9 ++--- .../writing-and-running-benchmarks.md | 40 ++++++++++--------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/benchmark/common.js b/benchmark/common.js index 0bb3fa3dfae32f..cff0c705d6dd7a 100644 --- a/benchmark/common.js +++ b/benchmark/common.js @@ -117,10 +117,9 @@ class Benchmark { const [, key, value] = match; if (configs[key] !== undefined) { cliOptions[key] ||= []; - cliOptions[key].push( - // Infer the type from the config object and parse accordingly - typeof configs[key][0] === 'number' ? +value : value, - ); + const configType = typeof configs[key][0]; + const configValue = configType === 'number' ? +value : configType === 'boolean' ? value === 'true' : value; + cliOptions[key].push(configValue); } else { extraOptions[key] = value; } @@ -140,7 +139,7 @@ class Benchmark { const values = options[key]; for (const value of values) { - if (typeof value !== 'number' && typeof value !== 'string') { + if (typeof value !== 'number' && typeof value !== 'string' && typeof value !== 'boolean') { throw new TypeError( `configuration "${key}" had type ${typeof value}`); } diff --git a/doc/contributing/writing-and-running-benchmarks.md b/doc/contributing/writing-and-running-benchmarks.md index a60a06b695f242..00d0542c5dbd18 100644 --- a/doc/contributing/writing-and-running-benchmarks.md +++ b/doc/contributing/writing-and-running-benchmarks.md @@ -2,23 +2,27 @@ ## Table of contents -* [Prerequisites](#prerequisites) - * [HTTP benchmark requirements](#http-benchmark-requirements) - * [HTTPS benchmark requirements](#https-benchmark-requirements) - * [HTTP/2 benchmark requirements](#http2-benchmark-requirements) - * [Benchmark analysis requirements](#benchmark-analysis-requirements) -* [Running benchmarks](#running-benchmarks) - * [Running individual benchmarks](#running-individual-benchmarks) - * [Calibrating the number of iterations with calibrate-n.js](#calibrating-the-number-of-iterations-with-calibrate-njs) - * [Running all benchmarks](#running-all-benchmarks) - * [Specifying CPU Cores for Benchmarks with run.js](#specifying-cpu-cores-for-benchmarks-with-runjs) - * [Filtering benchmarks](#filtering-benchmarks) - * [Comparing Node.js versions](#comparing-nodejs-versions) - * [Comparing parameters](#comparing-parameters) - * [Running benchmarks on the CI](#running-benchmarks-on-the-ci) -* [Creating a benchmark](#creating-a-benchmark) - * [Basics of a benchmark](#basics-of-a-benchmark) - * [Creating an HTTP benchmark](#creating-an-http-benchmark) +* [How to write and run benchmarks in Node.js core](#how-to-write-and-run-benchmarks-in-nodejs-core) + * [Table of contents](#table-of-contents) + * [Prerequisites](#prerequisites) + * [HTTP benchmark requirements](#http-benchmark-requirements) + * [HTTPS benchmark requirements](#https-benchmark-requirements) + * [HTTP/2 benchmark requirements](#http2-benchmark-requirements) + * [Benchmark analysis requirements](#benchmark-analysis-requirements) + * [Running benchmarks](#running-benchmarks) + * [Setting CPU Frequency scaling governor to "performance"](#setting-cpu-frequency-scaling-governor-to-performance) + * [Running individual benchmarks](#running-individual-benchmarks) + * [Calibrating the number of iterations with calibrate-n.js](#calibrating-the-number-of-iterations-with-calibrate-njs) + * [Running all benchmarks](#running-all-benchmarks) + * [Specifying CPU Cores for Benchmarks with run.js](#specifying-cpu-cores-for-benchmarks-with-runjs) + * [Filtering benchmarks](#filtering-benchmarks) + * [Grouping benchmarks](#grouping-benchmarks) + * [Comparing Node.js versions](#comparing-nodejs-versions) + * [Comparing parameters](#comparing-parameters) + * [Running benchmarks on the CI](#running-benchmarks-on-the-ci) + * [Creating a benchmark](#creating-a-benchmark) + * [Basics of a benchmark](#basics-of-a-benchmark) + * [Creating an HTTP benchmark](#creating-an-http-benchmark) ## Prerequisites @@ -562,7 +566,7 @@ The arguments of `createBenchmark` are: * `configs` {Object} The benchmark parameters. `createBenchmark` will run all possible combinations of these parameters, unless specified otherwise. Each configuration is a property with an array of possible values. - The configuration values can only be strings or numbers. + The configuration values can be strings, numbers, or booleans. * `options` {Object} The benchmark options. Supported options: * `flags` {Array} Contains node-specific command line flags to pass to the child process. From ad0c9acd49a66fdeecdefdd77f6d454c6b65450f Mon Sep 17 00:00:00 2001 From: SeokhunEom Date: Mon, 6 Oct 2025 19:24:11 +0900 Subject: [PATCH 2/2] benchmark: use boolean options in benchmark tests Use boolean values for randomUUID benchmark and deprecate benchmark instead of 0/1. --- benchmark/crypto/randomUUID.js | 3 +-- benchmark/util/deprecate.js | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/benchmark/crypto/randomUUID.js b/benchmark/crypto/randomUUID.js index cca05242874738..e03c502998188d 100644 --- a/benchmark/crypto/randomUUID.js +++ b/benchmark/crypto/randomUUID.js @@ -5,11 +5,10 @@ const { randomUUID } = require('crypto'); const bench = common.createBenchmark(main, { n: [1e7], - disableEntropyCache: [0, 1], + disableEntropyCache: [false, true], }); function main({ n, disableEntropyCache }) { - disableEntropyCache = !!disableEntropyCache; bench.start(); for (let i = 0; i < n; ++i) randomUUID({ disableEntropyCache }); diff --git a/benchmark/util/deprecate.js b/benchmark/util/deprecate.js index a94a7606321003..13ddcec8ecda02 100644 --- a/benchmark/util/deprecate.js +++ b/benchmark/util/deprecate.js @@ -5,7 +5,7 @@ const assert = require('assert'); const bench = common.createBenchmark(main, { n: [1e5], - modifyPrototype: [1, 0], + modifyPrototype: [true, false], emitWarningSync: [1, 0], }, { flags: ['--expose-internals'], @@ -23,7 +23,7 @@ function main({ n, modifyPrototype, emitWarningSync }) { 'This function is deprecated', 'DEP0000', emitWarningSync, - !!modifyPrototype, + modifyPrototype, ); let sum = 0;