Skip to content

Commit 152396c

Browse files
committed
Support custom "--file" path and auto-create file if missing
1 parent f50e147 commit 152396c

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/lib/testing/perf-regression.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313

1414
import { ConstraintSystemSummary } from '../provable/core/provable-context.js';
15+
import minimist from 'minimist';
1516
import fs from 'fs';
1617
import path from 'path';
1718

@@ -40,10 +41,29 @@ type PerfStack = {
4041
methodName?: string; // required for prove; optional for compile
4142
};
4243

43-
const FILE_PATH = path.join(process.cwd(), './tests/perf-regression/perf-regression.json');
44-
const DUMP = flag('--dump');
45-
const CHECK = flag('--check');
46-
const SILENT = flag('--silent');
44+
const argv = minimist(process.argv.slice(2), {
45+
boolean: ['dump', 'check', 'silent'],
46+
string: ['file'],
47+
alias: { f: 'file' },
48+
});
49+
50+
const DUMP = Boolean(argv.dump);
51+
const CHECK = Boolean(argv.check);
52+
const SILENT = Boolean(argv.silent);
53+
54+
const FILE_PATH = path.isAbsolute(argv.file ?? '')
55+
? argv.file
56+
: path.join(
57+
process.cwd(),
58+
argv.file ? argv.file : './tests/perf-regression/perf-regression.json'
59+
);
60+
61+
// Create directory & file if missing (only on dump)
62+
if (DUMP) {
63+
const dir = path.dirname(FILE_PATH);
64+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
65+
if (!fs.existsSync(FILE_PATH)) fs.writeFileSync(FILE_PATH, '{}', 'utf8');
66+
}
4767

4868
// Stops the process after the N-th end() call, if STOP_AFTER env is set.
4969
// If STOP_AFTER is not set or invalid, the script runs through normally.
@@ -52,7 +72,7 @@ const STOP_AFTER = Number.isFinite(Number(process.env.STOP_AFTER ?? ''))
5272
: undefined;
5373

5474
/**
55-
* Create a new performance tracking session for a contract.
75+
* Create a new performance tracking session for a program.
5676
*
5777
* @param programName Name of the program (key in perf-regression.json)
5878
* @param methodsSummary Optional methods analysis (required for prove checks)
@@ -263,10 +283,6 @@ const Performance = {
263283

264284
// HELPERS
265285

266-
function flag(name: string) {
267-
return process.argv.includes(name);
268-
}
269-
270286
/**
271287
* Compare a measured time/digest against stored baselines.
272288
* Throws an error if regression exceeds tolerance.

0 commit comments

Comments
 (0)