Skip to content

Commit f50e147

Browse files
committed
Add --silent flag and improve logging controls in performance regression framework
1 parent c23d7f1 commit f50e147

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/lib/testing/perf-regression.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type PerfStack = {
4343
const FILE_PATH = path.join(process.cwd(), './tests/perf-regression/perf-regression.json');
4444
const DUMP = flag('--dump');
4545
const CHECK = flag('--check');
46+
const SILENT = flag('--silent');
4647

4748
// Stops the process after the N-th end() call, if STOP_AFTER env is set.
4849
// If STOP_AFTER is not set or invalid, the script runs through normally.
@@ -55,6 +56,8 @@ const STOP_AFTER = Number.isFinite(Number(process.env.STOP_AFTER ?? ''))
5556
*
5657
* @param programName Name of the program (key in perf-regression.json)
5758
* @param methodsSummary Optional methods analysis (required for prove checks)
59+
* @param log Optional boolean (default: true). If `--silent` is passed via CLI,
60+
* it overrides this and disables all logs.
5861
* @returns An object with `start()` and `end()` methods
5962
*/
6063
function createPerformanceSession(
@@ -65,6 +68,8 @@ function createPerformanceSession(
6568
const perfStack: PerfStack[] = [];
6669
let endCounter = 0;
6770

71+
const shouldLog = SILENT ? false : log;
72+
6873
function maybeStop() {
6974
if (STOP_AFTER && STOP_AFTER > 0) {
7075
endCounter++;
@@ -93,7 +98,8 @@ function createPerformanceSession(
9398

9499
/**
95100
* End the most recent measurement and:
96-
* - Optionally log results to console
101+
* - Logs results to the console by default. This can be disabled by setting `log` to `false`
102+
* when creating the session, or by passing the `--silent` flag when running the file.
97103
* - Dump into baseline JSON (if `--dump`)
98104
* - Check against baseline (if `--check`)
99105
*/
@@ -106,7 +112,7 @@ function createPerformanceSession(
106112

107113
// Base logging — only if log is enabled
108114
// — shows contract.method for prove
109-
if (log && label) {
115+
if (shouldLog && label) {
110116
console.log(
111117
`${label} ${programName ?? ''}${
112118
label === 'prove' && methodName ? '.' + methodName : ''
@@ -242,9 +248,10 @@ const Performance = {
242248
* @param methodsSummary Optional analysis of ZkProgram methods, required when
243249
* measuring prove performance.
244250
* @param log Optional boolean flag (default: `true`).
245-
* When set to `false`, disables all console output for both general labels
246-
* and compile/prove phase logs.
247-
*/
251+
* - When set to `false`, disables all console output for both general labels
252+
* and compile/prove phase logs.
253+
* - When the `--silent` flag is provided, it overrides this setting and disables
254+
* all logging regardless of the `log` value. */
248255
create(
249256
programName?: string,
250257
methodsSummary?: Record<string, ConstraintSystemSummary>,

0 commit comments

Comments
 (0)