Skip to content

Commit 28538f2

Browse files
RafaelGSSaduh95
authored andcommitted
benchmark: add --track to benchmark
This option will measure how long the benchmark takes to run. Example: ``` $ ./node benchmark/run.js --track assert assert/assertion-error.js assert/assertion-error.js size=2 n=200: 22,987.24012781365 assert/assertion-error.js size=75 n=200: 296.2362823364434 [740ms] assert/assertion-error.js ... ``` Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com> PR-URL: #59174 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
1 parent a28d804 commit 28538f2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

benchmark/run.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const path = require('path');
44
const { spawn, fork } = require('node:child_process');
55
const CLI = require('./_cli.js');
6+
const { styleText } = require('node:util');
67

78
const cli = new CLI(`usage: ./node run.js [options] [--] <category> ...
89
Run each benchmark in the <category> directory a single time, more than one
@@ -16,6 +17,7 @@ const cli = new CLI(`usage: ./node run.js [options] [--] <category> ...
1617
Default: 1
1718
--set variable=value set benchmark variable (can be repeated)
1819
--format [simple|csv] optional value that specifies the output format
20+
--track Display the time elapsed to run each benchmark file.
1921
test only run a single configuration from the options
2022
matrix
2123
all each benchmark category is run one after the other
@@ -25,7 +27,7 @@ const cli = new CLI(`usage: ./node run.js [options] [--] <category> ...
2527
--set CPUSET=0-2 Specifies that benchmarks should run on CPU cores 0 to 2.
2628
2729
Note: The CPUSET format should match the specifications of the 'taskset' command on your system.
28-
`, { arrayArgs: ['set', 'filter', 'exclude'] });
30+
`, { arrayArgs: ['set', 'filter', 'exclude'], boolArgs: ['track'] });
2931

3032
const benchmarks = cli.benchmarks();
3133

@@ -107,7 +109,12 @@ async function run() {
107109
}
108110

109111
while (runs-- > 0) {
112+
const start = performance.now();
110113
await runBenchmark(filename);
114+
if (format !== 'csv' && cli.optional.track) {
115+
const ms = styleText(['bold', 'yellow'], `${Math.round(performance.now() - start)}ms`);
116+
console.log(`[${ms}] ${filename}`);
117+
}
111118
}
112119
}
113120
}

0 commit comments

Comments
 (0)