Files
callstack__agent-device/scripts/png-crop-benchmark/args.ts
T
Michał Pierzchała 9aa6465768 perf(scripts): add a device-free PNG crop benchmark (#2505)
* perf(scripts): add a device-free PNG crop benchmark

`pnpm bench:png-crop` runs the whole-image pipeline and the shipped region crop
over the same bytes in one process, so the comparison holds the capture content,
the deflate stream, and the machine fixed. The corpus is generated, which keeps a
run at seconds with no device; real captures join the same table via `--file`, and
each corpus entry prints its compressed size so an unrealistic corpus is visible.

The README records what the measurements said, including the case the encoder
policy loses: `None` on every scanline is faster everywhere but writes about 1.7x
more bytes than a filtered encoding on smooth low-frequency content.

* chore(gates): run the PNG crop benchmark's model tests in unit-core

Registers scripts/png-crop-benchmark/*.test.ts so the timing summary that the
report is built from stays covered without a device lane.
2026-09-12 18:23:28 +00:00

37 lines
1.1 KiB
TypeScript

/** The command line `pnpm bench:png-crop` accepts. */
export type BenchmarkOptions = Readonly<{
rounds: number;
jsonPath: string | undefined;
captureFiles: readonly string[];
}>;
const DEFAULT_ROUNDS = 5;
export function parseBenchmarkArgs(argv: readonly string[]): BenchmarkOptions {
return {
rounds: readNumber(argv, '--rounds') ?? DEFAULT_ROUNDS,
jsonPath: readString(argv, '--json'),
captureFiles: readAll(argv, '--file'),
};
}
function readNumber(argv: readonly string[], flag: string): number | undefined {
const value = readString(argv, flag);
const parsed = value === undefined ? Number.NaN : Number(value);
return Number.isFinite(parsed) && parsed > 0 ? Math.round(parsed) : undefined;
}
function readString(argv: readonly string[], flag: string): string | undefined {
const index = argv.indexOf(flag);
return index >= 0 ? argv[index + 1] : undefined;
}
function readAll(argv: readonly string[], flag: string): string[] {
const values: string[] = [];
argv.forEach((entry, index) => {
if (entry === flag && argv[index + 1] !== undefined) values.push(argv[index + 1]!);
});
return values;
}