From 5c35b8bc5753c5be3c7b5cffee530cafdc3b4883 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Tue, 22 Jul 2025 14:15:46 -0300 Subject: [PATCH] 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 --- benchmark/run.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/benchmark/run.js b/benchmark/run.js index ea0dc415e91ec6..4948292437fdde 100644 --- a/benchmark/run.js +++ b/benchmark/run.js @@ -3,6 +3,7 @@ const path = require('path'); const { spawn, fork } = require('node:child_process'); const CLI = require('./_cli.js'); +const { styleText } = require('node:util'); const cli = new CLI(`usage: ./node run.js [options] [--] ... Run each benchmark in the directory a single time, more than one @@ -16,6 +17,7 @@ const cli = new CLI(`usage: ./node run.js [options] [--] ... Default: 1 --set variable=value set benchmark variable (can be repeated) --format [simple|csv] optional value that specifies the output format + --track Display the time elapsed to run each benchmark file. test only run a single configuration from the options matrix all each benchmark category is run one after the other @@ -25,7 +27,7 @@ const cli = new CLI(`usage: ./node run.js [options] [--] ... --set CPUSET=0-2 Specifies that benchmarks should run on CPU cores 0 to 2. Note: The CPUSET format should match the specifications of the 'taskset' command on your system. -`, { arrayArgs: ['set', 'filter', 'exclude'] }); +`, { arrayArgs: ['set', 'filter', 'exclude'], boolArgs: ['track'] }); const benchmarks = cli.benchmarks(); @@ -107,7 +109,12 @@ async function run() { } while (runs-- > 0) { + const start = performance.now(); await runBenchmark(filename); + if (format !== 'csv' && cli.optional.track) { + const ms = styleText(['bold', 'yellow'], `${Math.round(performance.now() - start)}ms`); + console.log(`[${ms}] ${filename}`); + } } } }