Skip to content

Commit 39be09a

Browse files
committed
benchmark: add benchmark groups
Add the `byGroup` option to have benchmark parameter grouping. The environment variable `NODE_RUN_BENCHMARK_GROUPS` allows to benchmark only certain groups: `NODE_RUN_BENCHMARK_GROUPS=groupA,groupB`. Fixes: nodejs#26425
1 parent 12622c5 commit 39be09a

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

benchmark/common.js

+24-6
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,34 @@ class Benchmark {
2424

2525
// Parse job-specific configuration from the command line arguments
2626
const argv = process.argv.slice(2);
27-
const parsed_args = this._parseArgs(argv, configs, options);
28-
this.options = parsed_args.cli;
29-
this.extra_options = parsed_args.extra;
27+
28+
// The configuration list as a queue of jobs
29+
this.queue = [];
30+
31+
if (options.byGroup) {
32+
const groups = process.env.NODE_RUN_BENCHMARK_GROUPS ?
33+
process.env.NODE_RUN_BENCHMARK_GROUPS.split(',') :
34+
Object.keys(configs);
35+
36+
for (const key of groups) {
37+
const config = configs[key];
38+
config.group = key;
39+
const parsed_args = this._parseArgs(argv, config, options);
40+
this.options = parsed_args.cli;
41+
this.extra_options = parsed_args.extra;
42+
this.queue = this.queue.concat(this._queue(this.options));
43+
}
44+
} else {
45+
const parsed_args = this._parseArgs(argv, configs, options);
46+
this.options = parsed_args.cli;
47+
this.extra_options = parsed_args.extra;
48+
this.queue = this._queue(this.options);
49+
}
50+
3051
if (options.flags) {
3152
this.flags = this.flags.concat(options.flags);
3253
}
3354

34-
// The configuration list as a queue of jobs
35-
this.queue = this._queue(this.options);
36-
3755
// The configuration of the current job, head of the queue
3856
this.config = this.queue[0];
3957

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

+18-2
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,24 @@ The arguments of `createBenchmark` are:
444444
possible combinations of these parameters, unless specified otherwise.
445445
Each configuration is a property with an array of possible values.
446446
The configuration values can only be strings or numbers.
447-
* `options` {Object} The benchmark options. At the moment only the `flags`
448-
option for specifying command line flags is supported.
447+
* `options` {Object} The benchmark options:
448+
* `flags` option for specifying command line flags is supported
449+
* `byGroup` option for processing `configs` by groups:
450+
451+
```js
452+
const bench = common.createBenchmark(main, {
453+
groupA: {
454+
source: ['array'],
455+
len: [10, 2048],
456+
n: [50],
457+
},
458+
groupB: {
459+
source: ['buffer', 'string'],
460+
len: [2048],
461+
n: [50, 2048],
462+
}
463+
}, { byGroup: true });
464+
```
449465

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

0 commit comments

Comments
 (0)