swadhinbiswas 🔧 fix: Benchmark regression gate output format · 7/28/2026
763b9b5
59 lines · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
name: Benchmark Regression Gate

on:
  pull_request:
    branches: [main]
  push:
    branches: [main]

jobs:
  benchmark:
    name: RPS Regression Check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Cache cargo registry
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-bench-${{ hashFiles('**/Cargo.lock') }}

      - name: Run Regression Check
        run: |
          # 1. Build and run on PR branch
          cargo build --release -p justapi-bench --bin justapi-bench
          cargo run --release -p justapi-bench --bin justapi-bench -- --duration 10 > pr_bench.txt
          PR_RPS=$(grep -oP '\K[0-9]+(?= ops/sec)' pr_bench.txt || echo "0")
          
          # 2. Checkout main branch and run
          git checkout main
          cargo build --release -p justapi-bench --bin justapi-bench
          cargo run --release -p justapi-bench --bin justapi-bench -- --duration 10 > main_bench.txt
          MAIN_RPS=$(grep -oP '\K[0-9]+(?= ops/sec)' main_bench.txt || echo "0")
          
          echo "Main RPS: $MAIN_RPS"
          echo "PR RPS: $PR_RPS"
          
          if [ "$MAIN_RPS" -eq 0 ]; then
            echo "Failed to extract main RPS"
            exit 1
          fi
          
          # 3. Compare (Fail if PR_RPS < 0.95 * MAIN_RPS)
          THRESHOLD=$(echo "$MAIN_RPS * 0.95" | bc | cut -d. -f1)
          if [ "$PR_RPS" -lt "$THRESHOLD" ]; then
            echo "RPS dropped by >5%! Expected at least $THRESHOLD, got $PR_RPS"
            exit 1
          else
            echo "RPS is within acceptable bounds."
          fi