Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: add benchmark groups #39285

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,37 @@ class Benchmark {
this.name = require.main.filename.slice(__dirname.length + 1);

// Execution arguments i.e. flags used to run the jobs
this.flags = process.env.NODE_BENCHMARK_FLAGS ?
process.env.NODE_BENCHMARK_FLAGS.split(/\s+/) :
[];
this.flags = process.env.NODE_BENCHMARK_FLAGS?.split(/\s+/) ?? [];

// 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.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
* `byGroup` option for processing `configs` by groups:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚙️ (optional) Perhaps it's better to use the plural for consistency:

Suggested change
* `byGroup` option for processing `configs` by groups:
* `byGroups` 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