From d19065e14a2f8a853b48b24ddca30089019c2fdd Mon Sep 17 00:00:00 2001 From: Kazuki Yamada Date: Sat, 28 Mar 2026 23:36:54 +0900 Subject: [PATCH] perf(ci): Extract benchmark-history script and increase runs - Extract inline benchmark script to bench-run-history.mjs - Increase measurement runs from 10/20/10 to 20/30/20 to match perf-benchmark.yml for consistency Co-Authored-By: Claude Opus 4.6 (1M context) --- .../perf-benchmark/bench-run-history.mjs | 44 +++++++++++++++ .github/workflows/perf-benchmark-history.yml | 56 ++----------------- 2 files changed, 48 insertions(+), 52 deletions(-) create mode 100644 .github/scripts/perf-benchmark/bench-run-history.mjs diff --git a/.github/scripts/perf-benchmark/bench-run-history.mjs b/.github/scripts/perf-benchmark/bench-run-history.mjs new file mode 100644 index 00000000..99fb37b4 --- /dev/null +++ b/.github/scripts/perf-benchmark/bench-run-history.mjs @@ -0,0 +1,44 @@ +import { execFileSync } from 'node:child_process'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { writeFileSync } from 'node:fs'; + +const dir = process.argv[2]; +const output = join(tmpdir(), 'repomix-bench-output.txt'); +const runs = Number(process.env.BENCH_RUNS) || 20; +const bin = join(dir, 'bin', 'repomix.cjs'); + +// Warmup runs to stabilize OS page cache and JIT +for (let i = 0; i < 2; i++) { + try { + execFileSync(process.execPath, [bin, dir, '--output', output], { stdio: 'ignore' }); + } catch {} +} + +// Measurement runs +const times = []; +for (let i = 0; i < runs; i++) { + const start = Date.now(); + execFileSync(process.execPath, [bin, dir, '--output', output], { stdio: 'ignore' }); + times.push(Date.now() - start); +} + +times.sort((a, b) => a - b); +const median = times[Math.floor(times.length / 2)]; +const q1 = times[Math.floor(times.length * 0.25)]; +const q3 = times[Math.floor(times.length * 0.75)]; +const iqr = q3 - q1; + +const osName = process.env.RUNNER_OS; + +// Output in customSmallerIsBetter format for github-action-benchmark +const result = [{ + name: `Repomix Pack (${osName})`, + unit: 'ms', + value: median, + range: '±' + iqr, + extra: `Median of ${runs} runs\nQ1: ${q1}ms, Q3: ${q3}ms\nAll times: ${times.join(', ')}ms`, +}]; + +writeFileSync(join(process.env.RUNNER_TEMP, 'bench-result.json'), JSON.stringify(result)); +console.log(`${osName}: median=${median}ms (±${iqr}ms)`); diff --git a/.github/workflows/perf-benchmark-history.yml b/.github/workflows/perf-benchmark-history.yml index 191de1a8..5fbaafc7 100644 --- a/.github/workflows/perf-benchmark-history.yml +++ b/.github/workflows/perf-benchmark-history.yml @@ -25,11 +25,11 @@ jobs: matrix: include: - os: ubuntu-latest - runs: 10 - - os: macos-latest runs: 20 + - os: macos-latest + runs: 30 - os: windows-latest - runs: 10 + runs: 20 steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: @@ -47,55 +47,7 @@ jobs: shell: bash env: BENCH_RUNS: ${{ matrix.runs }} - run: | - cat > "$RUNNER_TEMP/benchmark.mjs" << 'BENCHSCRIPT' - import { execFileSync } from 'node:child_process'; - import { tmpdir } from 'node:os'; - import { join } from 'node:path'; - import { writeFileSync } from 'node:fs'; - - const dir = process.argv[2]; - const output = join(tmpdir(), 'repomix-bench-output.txt'); - const runs = Number(process.env.BENCH_RUNS) || 10; - const bin = join(dir, 'bin', 'repomix.cjs'); - - // Warmup runs to stabilize OS page cache and JIT - for (let i = 0; i < 2; i++) { - try { - execFileSync(process.execPath, [bin, dir, '--output', output], { stdio: 'ignore' }); - } catch {} - } - - // Measurement runs - const times = []; - for (let i = 0; i < runs; i++) { - const start = Date.now(); - execFileSync(process.execPath, [bin, dir, '--output', output], { stdio: 'ignore' }); - times.push(Date.now() - start); - } - - times.sort((a, b) => a - b); - const median = times[Math.floor(times.length / 2)]; - const q1 = times[Math.floor(times.length * 0.25)]; - const q3 = times[Math.floor(times.length * 0.75)]; - const iqr = q3 - q1; - - const osName = process.env.RUNNER_OS; - - // Output in customSmallerIsBetter format for github-action-benchmark - const result = [{ - name: `Repomix Pack (${osName})`, - unit: 'ms', - value: median, - range: '±' + iqr, - extra: `Median of ${runs} runs\nQ1: ${q1}ms, Q3: ${q3}ms\nAll times: ${times.join(', ')}ms` - }]; - - writeFileSync(join(process.env.RUNNER_TEMP, 'bench-result.json'), JSON.stringify(result)); - console.log(`${osName}: median=${median}ms (±${iqr}ms)`); - BENCHSCRIPT - - node "$RUNNER_TEMP/benchmark.mjs" "$GITHUB_WORKSPACE" + run: node .github/scripts/perf-benchmark/bench-run-history.mjs "$GITHUB_WORKSPACE" - name: Upload benchmark result uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0