fix: calculate MAX_BATCHES correctly in Jest loop-runner

Previously, MAX_BATCHES was set to PERF_LOOP_COUNT directly (e.g., 250),
which caused the loop-runner to run 250 batches even though only 25
batches were needed to produce timing data (with BATCH_SIZE=10).

The bug was that timing markers only appeared for the first N batches
(where N = LOOP_COUNT / BATCH_SIZE), and the remaining batches were
wasted overhead.

Fix: Calculate MAX_BATCHES as ceil(LOOP_COUNT / BATCH_SIZE) + 1, capped
at LOOP_COUNT. This ensures only the necessary batches run:
- With LOOP_COUNT=250, BATCH_SIZE=10: MAX_BATCHES = 26 (not 250)

This significantly improves benchmark efficiency by eliminating wasted
Jest passes that don't contribute timing data.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Saurabh Misra 2026-01-31 06:47:01 +00:00
parent 2cee81bb5d
commit 5296dc8321

View file

@ -32,7 +32,11 @@ const internalRequire = createRequire(jestRunnerPath);
const runTest = internalRequire('./runTest').default;
// Configuration
const MAX_BATCHES = parseInt(process.env.CODEFLASH_PERF_LOOP_COUNT || '10000', 10);
const PERF_LOOP_COUNT = parseInt(process.env.CODEFLASH_PERF_LOOP_COUNT || '10000', 10);
const PERF_BATCH_SIZE = parseInt(process.env.CODEFLASH_PERF_BATCH_SIZE || '10', 10);
// MAX_BATCHES = how many batches needed to reach PERF_LOOP_COUNT iterations
// Add 1 to handle any rounding, but cap at PERF_LOOP_COUNT to avoid excessive batches
const MAX_BATCHES = Math.min(Math.ceil(PERF_LOOP_COUNT / PERF_BATCH_SIZE) + 1, PERF_LOOP_COUNT);
const TARGET_DURATION_MS = parseInt(process.env.CODEFLASH_PERF_TARGET_DURATION_MS || '10000', 10);
const MIN_BATCHES = parseInt(process.env.CODEFLASH_PERF_MIN_LOOPS || '5', 10);