mirror of
https://github.com/nodejs/node.git
synced 2025-04-29 06:19:07 +00:00
benchmark: add --runs support to run.js
PR-URL: https://github.com/nodejs/node/pull/55158 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
This commit is contained in:
parent
7ae193d19f
commit
7c0cc12f0b
@ -12,6 +12,8 @@ const cli = new CLI(`usage: ./node run.js [options] [--] <category> ...
|
|||||||
(can be repeated)
|
(can be repeated)
|
||||||
--exclude pattern excludes scripts matching <pattern> (can be
|
--exclude pattern excludes scripts matching <pattern> (can be
|
||||||
repeated)
|
repeated)
|
||||||
|
--runs variable=value set the amount of benchmark suite execution.
|
||||||
|
Default: 1
|
||||||
--set variable=value set benchmark variable (can be repeated)
|
--set variable=value set benchmark variable (can be repeated)
|
||||||
--format [simple|csv] optional value that specifies the output format
|
--format [simple|csv] optional value that specifies the output format
|
||||||
test only run a single configuration from the options
|
test only run a single configuration from the options
|
||||||
@ -45,8 +47,7 @@ if (format === 'csv') {
|
|||||||
console.log('"filename", "configuration", "rate", "time"');
|
console.log('"filename", "configuration", "rate", "time"');
|
||||||
}
|
}
|
||||||
|
|
||||||
(function recursive(i) {
|
function runBenchmark(filename) {
|
||||||
const filename = benchmarks[i];
|
|
||||||
const scriptPath = path.resolve(__dirname, filename);
|
const scriptPath = path.resolve(__dirname, filename);
|
||||||
|
|
||||||
const args = cli.test ? ['--test'] : cli.optional.set;
|
const args = cli.test ? ['--test'] : cli.optional.set;
|
||||||
@ -63,11 +64,7 @@ if (format === 'csv') {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format !== 'csv') {
|
return new Promise((resolve, reject) => {
|
||||||
console.log();
|
|
||||||
console.log(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
child.on('message', (data) => {
|
child.on('message', (data) => {
|
||||||
if (data.type !== 'report') {
|
if (data.type !== 'report') {
|
||||||
return;
|
return;
|
||||||
@ -90,15 +87,29 @@ if (format === 'csv') {
|
|||||||
console.log(`${data.name} ${conf}: ${rate}`);
|
console.log(`${data.name} ${conf}: ${rate}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
child.once('close', (code) => {
|
child.once('close', (code) => {
|
||||||
if (code) {
|
if (code) {
|
||||||
process.exit(code);
|
reject(code);
|
||||||
}
|
} else {
|
||||||
|
resolve(code);
|
||||||
// If there are more benchmarks execute the next
|
|
||||||
if (i + 1 < benchmarks.length) {
|
|
||||||
recursive(i + 1);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})(0);
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
for (let i = 0; i < benchmarks.length; ++i) {
|
||||||
|
let runs = cli.optional.runs ?? 1;
|
||||||
|
const filename = benchmarks[i];
|
||||||
|
if (format !== 'csv') {
|
||||||
|
console.log();
|
||||||
|
console.log(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (runs-- > 0) {
|
||||||
|
await runBenchmark(filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run();
|
||||||
|
@ -174,6 +174,16 @@ It is possible to execute more groups by adding extra process arguments.
|
|||||||
node benchmark/run.js assert async_hooks
|
node benchmark/run.js assert async_hooks
|
||||||
```
|
```
|
||||||
|
|
||||||
|
It's also possible to execute the benchmark more than once using the
|
||||||
|
`--runs` flag.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
node benchmark/run.js --runs 10 assert async_hooks
|
||||||
|
```
|
||||||
|
|
||||||
|
This command will run the benchmark files in `benchmark/assert` and `benchmark/async_hooks`
|
||||||
|
10 times each.
|
||||||
|
|
||||||
#### Specifying CPU Cores for Benchmarks with run.js
|
#### Specifying CPU Cores for Benchmarks with run.js
|
||||||
|
|
||||||
When using `run.js` to execute a group of benchmarks,
|
When using `run.js` to execute a group of benchmarks,
|
||||||
|
Loading…
Reference in New Issue
Block a user