Skip to content

Commit

Permalink
benchmark: add benchmark groups
Browse files Browse the repository at this point in the history
Add the `byGroup` option to have parameter grouping.
The environment variable `NODE_RUN_BENCHMARK_GROUPS` allows to benchmark
only certain groups: `NODE_RUN_BENCHMARK_GROUPS=groupA,groupB`.

Fixes: nodejs#26425
  • Loading branch information
Mesteery committed Jul 6, 2021
1 parent 12622c5 commit cdebfc6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
30 changes: 24 additions & 6 deletions benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,34 @@ class Benchmark {

// Parse job-specific configuration from the command line arguments
const argv = process.argv.slice(2);
const parsed_args = this._parseArgs(argv, configs, options);
this.options = parsed_args.cli;
this.extra_options = parsed_args.extra;

// The configuration list as a queue of jobs
this.queue = [];

if (options.byGroup) {
const groups = process.env.hasOwnProperty('NODE_RUN_BENCHMARK_GROUPS') ?
process.env.NODE_RUN_BENCHMARK_GROUPS.split(',') :
Object.keys(configs);

for (const key of groups) {
const config = configs[key];
config.group = key;
const parsed_args = this._parseArgs(argv, config, options);
this.options = parsed_args.cli;
this.extra_options = parsed_args.extra;
this.queue = this.queue.concat(this._queue(this.options));
}
} else {
const parsed_args = this._parseArgs(argv, configs, options);
this.options = parsed_args.cli;
this.extra_options = parsed_args.extra;
this.queue = this._queue(this.options);
}

if (options.flags) {
this.flags = this.flags.concat(options.flags);
}

// The configuration list as a queue of jobs
this.queue = this._queue(this.options);

// The configuration of the current job, head of the queue
this.config = this.queue[0];

Expand Down
20 changes: 18 additions & 2 deletions doc/guides/writing-and-running-benchmarks.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,24 @@ The arguments of `createBenchmark` are:
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.
* `options` {Object} The benchmark options. At the moment only the `flags`
option for specifying command line flags is supported.
* `options` {Object} The benchmark options:
* `flags` option for specifying command line flags is supported
* `byGroup` option for processing `configs` by groups:

```js
const bench = common.createBenchmark(main, {
groupA: {
source: ['array'],
len: [10, 2048],
n: [50],
},
groupB: {
source: ['buffer', 'string'],
len: [2048],
n: [50, 2048],
}
}, { byGroup: true });
```

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

0 comments on commit cdebfc6

Please sign in to comment.