Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6186b3e

Browse filesBrowse files
mscdexruyadorno
authored andcommitted
benchmark: introduce benchmark combination filtering
PR-URL: #45735 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent e2698c0 commit 6186b3e
Copy full SHA for 6186b3e

File tree

Expand file treeCollapse file tree

2 files changed

+28
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+28
-3
lines changed
Open diff view settings
Collapse file

‎benchmark/common.js‎

Copy file name to clipboardExpand all lines: benchmark/common.js
+22-1Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
const child_process = require('child_process');
44
const http_benchmarkers = require('./_http-benchmarkers.js');
55

6+
function allow() {
7+
return true;
8+
}
9+
610
class Benchmark {
711
constructor(fn, configs, options = {}) {
812
// Used to make sure a benchmark only start a timer once
@@ -31,9 +35,17 @@ class Benchmark {
3135
this.flags = this.flags.concat(options.flags);
3236
}
3337

38+
if (typeof options.combinationFilter === 'function')
39+
this.combinationFilter = options.combinationFilter;
40+
else
41+
this.combinationFilter = allow;
42+
3443
// The configuration list as a queue of jobs
3544
this.queue = this._queue(this.options);
3645

46+
if (this.queue.length === 0)
47+
return;
48+
3749
// The configuration of the current job, head of the queue
3850
this.config = this.queue[0];
3951

@@ -108,6 +120,7 @@ class Benchmark {
108120
_queue(options) {
109121
const queue = [];
110122
const keys = Object.keys(options);
123+
const { combinationFilter } = this;
111124

112125
// Perform a depth-first walk through all options to generate a
113126
// configuration list that contains all combinations.
@@ -131,7 +144,15 @@ class Benchmark {
131144
if (keyIndex + 1 < keys.length) {
132145
recursive(keyIndex + 1, currConfig);
133146
} else {
134-
queue.push(currConfig);
147+
// Check if we should allow the current combination
148+
const allowed = combinationFilter({ ...currConfig });
149+
if (typeof allowed !== 'boolean') {
150+
throw new TypeError(
151+
'Combination filter must always return a boolean'
152+
);
153+
}
154+
if (allowed)
155+
queue.push(currConfig);
135156
}
136157
}
137158
}
Collapse file

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

Copy file name to clipboardExpand all lines: doc/contributing/writing-and-running-benchmarks.md
+6-2Lines changed: 6 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,12 @@ The arguments of `createBenchmark` are:
450450
possible combinations of these parameters, unless specified otherwise.
451451
Each configuration is a property with an array of possible values.
452452
The configuration values can only be strings or numbers.
453-
* `options` {Object} The benchmark options. At the moment only the `flags`
454-
option for specifying command line flags is supported.
453+
* `options` {Object} The benchmark options. Supported options:
454+
* `flags` {Array} Contains node-specific command line flags to pass to
455+
the child process.
456+
* `combinationFilter` {Function} Has a single parameter which is an object
457+
containing a combination of benchmark parameters. It should return `true`
458+
or `false` to indicate whether the combination should be included or not.
455459

456460
`createBenchmark` returns a `bench` object, which is used for timing
457461
the runtime of the benchmark. Run `bench.start()` after the initialization

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.