|
| 1 | +name: benchmark |
| 2 | +run-name: benchmark • ${{ github.event_name }} • ${{ github.ref_name }} |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: [ "feat/2.0.0" ] |
| 7 | + pull_request: |
| 8 | + branches: [ "feat/2.0.0" ] |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + profile: |
| 12 | + description: Benchmark profile |
| 13 | + required: true |
| 14 | + default: smoke |
| 15 | + type: choice |
| 16 | + options: |
| 17 | + - smoke |
| 18 | + - extended |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: read |
| 22 | + |
| 23 | +concurrency: |
| 24 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 25 | + cancel-in-progress: true |
| 26 | + |
| 27 | +jobs: |
| 28 | + benchmark: |
| 29 | + name: >- |
| 30 | + bench • ${{ matrix.label }} |
| 31 | + runs-on: ${{ matrix.os }} |
| 32 | + timeout-minutes: ${{ matrix.timeout_minutes }} |
| 33 | + |
| 34 | + strategy: |
| 35 | + fail-fast: false |
| 36 | + matrix: |
| 37 | + include: |
| 38 | + # default profile for push / PR |
| 39 | + - profile: smoke |
| 40 | + label: linux-smoke |
| 41 | + os: ubuntu-latest |
| 42 | + runs: 12 |
| 43 | + warmups: 3 |
| 44 | + cpus: "1.0" |
| 45 | + memory: "2g" |
| 46 | + timeout_minutes: 45 |
| 47 | + |
| 48 | + # extended profile for manual runs |
| 49 | + - profile: extended |
| 50 | + label: linux-extended |
| 51 | + os: ubuntu-latest |
| 52 | + runs: 16 |
| 53 | + warmups: 4 |
| 54 | + cpus: "1.0" |
| 55 | + memory: "2g" |
| 56 | + timeout_minutes: 50 |
| 57 | + |
| 58 | + - profile: extended |
| 59 | + label: macos-extended |
| 60 | + os: macos-latest |
| 61 | + runs: 12 |
| 62 | + warmups: 3 |
| 63 | + cpus: "" |
| 64 | + memory: "" |
| 65 | + timeout_minutes: 60 |
| 66 | + |
| 67 | + if: > |
| 68 | + (github.event_name != 'workflow_dispatch' && matrix.profile == 'smoke') || |
| 69 | + (github.event_name == 'workflow_dispatch' && matrix.profile == inputs.profile) |
| 70 | +
|
| 71 | + steps: |
| 72 | + - name: Checkout |
| 73 | + uses: actions/checkout@v6 |
| 74 | + |
| 75 | + - name: Set benchmark output path |
| 76 | + shell: bash |
| 77 | + run: | |
| 78 | + mkdir -p .cache/benchmarks |
| 79 | + echo "BENCH_JSON=.cache/benchmarks/codeclone-benchmark-${{ matrix.label }}.json" >> "$GITHUB_ENV" |
| 80 | +
|
| 81 | + - name: Build and run Docker benchmark (Linux) |
| 82 | + if: runner.os == 'Linux' |
| 83 | + env: |
| 84 | + RUNS: ${{ matrix.runs }} |
| 85 | + WARMUPS: ${{ matrix.warmups }} |
| 86 | + CPUS: ${{ matrix.cpus }} |
| 87 | + MEMORY: ${{ matrix.memory }} |
| 88 | + run: | |
| 89 | + ./benchmarks/run_docker_benchmark.sh |
| 90 | + cp .cache/benchmarks/codeclone-benchmark.json "$BENCH_JSON" |
| 91 | +
|
| 92 | + - name: Run local benchmark (macOS) |
| 93 | + if: runner.os == 'macOS' |
| 94 | + run: | |
| 95 | + uv run python benchmarks/run_benchmark.py \ |
| 96 | + --target . \ |
| 97 | + --runs "${{ matrix.runs }}" \ |
| 98 | + --warmups "${{ matrix.warmups }}" \ |
| 99 | + --tmp-dir "/tmp/codeclone-bench-${{ matrix.label }}" \ |
| 100 | + --output "$BENCH_JSON" |
| 101 | +
|
| 102 | + - name: Print benchmark summary |
| 103 | + if: always() |
| 104 | + shell: bash |
| 105 | + run: | |
| 106 | + python - <<'PY' |
| 107 | + import json |
| 108 | + import os |
| 109 | + from pathlib import Path |
| 110 | +
|
| 111 | + report_path = Path(os.environ["BENCH_JSON"]) |
| 112 | + if not report_path.exists(): |
| 113 | + print(f"benchmark report not found: {report_path}") |
| 114 | + raise SystemExit(1) |
| 115 | +
|
| 116 | + payload = json.loads(report_path.read_text(encoding="utf-8")) |
| 117 | + scenarios = payload.get("scenarios", []) |
| 118 | + comparisons = payload.get("comparisons", {}) |
| 119 | +
|
| 120 | + print("CodeClone benchmark summary") |
| 121 | + print(f"label={os.environ.get('RUNNER_OS','unknown').lower()} / {os.environ.get('GITHUB_JOB','benchmark')}") |
| 122 | + for scenario in scenarios: |
| 123 | + name = str(scenario.get("name", "unknown")) |
| 124 | + stats = scenario.get("stats_seconds", {}) |
| 125 | + median = float(stats.get("median", 0.0)) |
| 126 | + p95 = float(stats.get("p95", 0.0)) |
| 127 | + stdev = float(stats.get("stdev", 0.0)) |
| 128 | + digest = str(scenario.get("digest", "")) |
| 129 | + print( |
| 130 | + f"- {name:16s} median={median:.4f}s " |
| 131 | + f"p95={p95:.4f}s stdev={stdev:.4f}s digest={digest}" |
| 132 | + ) |
| 133 | +
|
| 134 | + if comparisons: |
| 135 | + print("ratios:") |
| 136 | + for key, value in sorted(comparisons.items()): |
| 137 | + print(f"- {key}={float(value):.3f}x") |
| 138 | +
|
| 139 | + summary_file = os.environ.get("GITHUB_STEP_SUMMARY") |
| 140 | + if not summary_file: |
| 141 | + raise SystemExit(0) |
| 142 | +
|
| 143 | + lines = [ |
| 144 | + f"## CodeClone benchmark — {os.environ.get('RUNNER_OS', 'unknown')} / ${{ matrix.label }}", |
| 145 | + "", |
| 146 | + f"- Tool: `{payload['tool']['name']} {payload['tool']['version']}`", |
| 147 | + f"- Target: `{payload['config']['target']}`", |
| 148 | + f"- Runs: `{payload['config']['runs']}`", |
| 149 | + f"- Warmups: `{payload['config']['warmups']}`", |
| 150 | + f"- Generated: `{payload['generated_at_utc']}`", |
| 151 | + "", |
| 152 | + "### Scenarios", |
| 153 | + "", |
| 154 | + "| Scenario | Median (s) | p95 (s) | Stdev (s) | Deterministic | Digest |", |
| 155 | + "|---|---:|---:|---:|:---:|---|", |
| 156 | + ] |
| 157 | +
|
| 158 | + for scenario in scenarios: |
| 159 | + stats = scenario.get("stats_seconds", {}) |
| 160 | + lines.append( |
| 161 | + "| " |
| 162 | + f"{scenario.get('name', '')} | " |
| 163 | + f"{float(stats.get('median', 0.0)):.4f} | " |
| 164 | + f"{float(stats.get('p95', 0.0)):.4f} | " |
| 165 | + f"{float(stats.get('stdev', 0.0)):.4f} | " |
| 166 | + f"{'yes' if bool(scenario.get('deterministic')) else 'no'} | " |
| 167 | + f"{scenario.get('digest', '')} |" |
| 168 | + ) |
| 169 | +
|
| 170 | + if comparisons: |
| 171 | + lines.extend( |
| 172 | + [ |
| 173 | + "", |
| 174 | + "### Ratios", |
| 175 | + "", |
| 176 | + "| Metric | Value |", |
| 177 | + "|---|---:|", |
| 178 | + ] |
| 179 | + ) |
| 180 | + for key, value in sorted(comparisons.items()): |
| 181 | + lines.append(f"| {key} | {float(value):.3f}x |") |
| 182 | +
|
| 183 | + with Path(summary_file).open("a", encoding="utf-8") as fh: |
| 184 | + fh.write("\n".join(lines) + "\n") |
| 185 | + PY |
| 186 | +
|
| 187 | + - name: Upload benchmark artifact |
| 188 | + if: always() |
| 189 | + uses: actions/upload-artifact@v7 |
| 190 | + with: |
| 191 | + name: codeclone-benchmark-${{ matrix.label }} |
| 192 | + path: ${{ env.BENCH_JSON }} |
| 193 | + if-no-files-found: error |
0 commit comments