Skip to content

Commit 5f9d07f

Browse files
committed
benchmark: allow boolean option values
Change createBenchmark to also accept booleans. Update writing-and-running-benchmarks.md and format the md.
1 parent 6797c6e commit 5f9d07f

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

benchmark/common.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,9 @@ class Benchmark {
117117
const [, key, value] = match;
118118
if (configs[key] !== undefined) {
119119
cliOptions[key] ||= [];
120-
cliOptions[key].push(
121-
// Infer the type from the config object and parse accordingly
122-
typeof configs[key][0] === 'number' ? +value : value,
123-
);
120+
const configType = typeof configs[key][0];
121+
const configValue = configType === 'number' ? +value : configType === 'boolean' ? value === 'true' : value;
122+
cliOptions[key].push(configValue);
124123
} else {
125124
extraOptions[key] = value;
126125
}
@@ -140,7 +139,7 @@ class Benchmark {
140139
const values = options[key];
141140

142141
for (const value of values) {
143-
if (typeof value !== 'number' && typeof value !== 'string') {
142+
if (typeof value !== 'number' && typeof value !== 'string' && typeof value !== 'boolean') {
144143
throw new TypeError(
145144
`configuration "${key}" had type ${typeof value}`);
146145
}

doc/contributing/writing-and-running-benchmarks.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22

33
## Table of contents
44

5-
* [Prerequisites](#prerequisites)
6-
* [HTTP benchmark requirements](#http-benchmark-requirements)
7-
* [HTTPS benchmark requirements](#https-benchmark-requirements)
8-
* [HTTP/2 benchmark requirements](#http2-benchmark-requirements)
9-
* [Benchmark analysis requirements](#benchmark-analysis-requirements)
10-
* [Running benchmarks](#running-benchmarks)
11-
* [Running individual benchmarks](#running-individual-benchmarks)
12-
* [Calibrating the number of iterations with calibrate-n.js](#calibrating-the-number-of-iterations-with-calibrate-njs)
13-
* [Running all benchmarks](#running-all-benchmarks)
14-
* [Specifying CPU Cores for Benchmarks with run.js](#specifying-cpu-cores-for-benchmarks-with-runjs)
15-
* [Filtering benchmarks](#filtering-benchmarks)
16-
* [Comparing Node.js versions](#comparing-nodejs-versions)
17-
* [Comparing parameters](#comparing-parameters)
18-
* [Running benchmarks on the CI](#running-benchmarks-on-the-ci)
19-
* [Creating a benchmark](#creating-a-benchmark)
20-
* [Basics of a benchmark](#basics-of-a-benchmark)
21-
* [Creating an HTTP benchmark](#creating-an-http-benchmark)
5+
* [How to write and run benchmarks in Node.js core](#how-to-write-and-run-benchmarks-in-nodejs-core)
6+
* [Table of contents](#table-of-contents)
7+
* [Prerequisites](#prerequisites)
8+
* [HTTP benchmark requirements](#http-benchmark-requirements)
9+
* [HTTPS benchmark requirements](#https-benchmark-requirements)
10+
* [HTTP/2 benchmark requirements](#http2-benchmark-requirements)
11+
* [Benchmark analysis requirements](#benchmark-analysis-requirements)
12+
* [Running benchmarks](#running-benchmarks)
13+
* [Setting CPU Frequency scaling governor to "performance"](#setting-cpu-frequency-scaling-governor-to-performance)
14+
* [Running individual benchmarks](#running-individual-benchmarks)
15+
* [Calibrating the number of iterations with calibrate-n.js](#calibrating-the-number-of-iterations-with-calibrate-njs)
16+
* [Running all benchmarks](#running-all-benchmarks)
17+
* [Specifying CPU Cores for Benchmarks with run.js](#specifying-cpu-cores-for-benchmarks-with-runjs)
18+
* [Filtering benchmarks](#filtering-benchmarks)
19+
* [Grouping benchmarks](#grouping-benchmarks)
20+
* [Comparing Node.js versions](#comparing-nodejs-versions)
21+
* [Comparing parameters](#comparing-parameters)
22+
* [Running benchmarks on the CI](#running-benchmarks-on-the-ci)
23+
* [Creating a benchmark](#creating-a-benchmark)
24+
* [Basics of a benchmark](#basics-of-a-benchmark)
25+
* [Creating an HTTP benchmark](#creating-an-http-benchmark)
2226

2327
## Prerequisites
2428

@@ -562,7 +566,7 @@ The arguments of `createBenchmark` are:
562566
* `configs` {Object} The benchmark parameters. `createBenchmark` will run all
563567
possible combinations of these parameters, unless specified otherwise.
564568
Each configuration is a property with an array of possible values.
565-
The configuration values can only be strings or numbers.
569+
The configuration values can be strings, numbers, or booleans.
566570
* `options` {Object} The benchmark options. Supported options:
567571
* `flags` {Array} Contains node-specific command line flags to pass to
568572
the child process.

0 commit comments

Comments
 (0)