Skip to content

Commit 2ce8f5d

Browse files
committed
Add benchmark job in CI
1 parent 157f03c commit 2ce8f5d

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

.github/workflows/pull_request.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,52 @@ jobs:
1919
license_header_check_project_name: "Swift.org"
2020
unacceptable_language_check_enabled: false
2121
format_check_enabled: false
22+
bench:
23+
name: Benchmark
24+
runs-on: ubuntu-latest
25+
env:
26+
BUILD_CMD: swift build -c release
27+
BENCH_CMD: .build/release/RegexBenchmark
28+
BASELINE_FILE: benchmark-baseline
29+
COMPARE_OUT_FILE: benchmark-results.txt
30+
steps:
31+
- name: Check out baseline branch
32+
uses: actions/checkout@v4
33+
with:
34+
ref: ${{ github.event.pull_request.base.sha }}
35+
path: base
36+
fetch-depth: 0
37+
- name: Build baseline branch
38+
working-directory: base
39+
run: |
40+
set -euo pipefail
41+
eval "$BUILD_CMD"
42+
- name: Run baseline benchmark
43+
working-directory: base
44+
run: |
45+
set -euo pipefail
46+
eval "$BENCH_CMD --save $RUNNER_TEMP/$BASELINE_FILE"
47+
test -s "$RUNNER_TEMP/$BASELINE_FILE" || { echo "Baseline not created at $BASELINE_FILE"; exit 1; }
48+
- name: Check out PR branch
49+
uses: actions/checkout@v4
50+
with:
51+
ref: ${{ github.event.pull_request.head.sha }}
52+
path: pr
53+
fetch-depth: 0
54+
- name: Build PR branch
55+
working-directory: pr
56+
run: |
57+
set -euo pipefail
58+
eval "$BUILD_CMD"
59+
- name: Run comparison benchmark (PR vs baseline)
60+
working-directory: pr
61+
run: |
62+
set -euo pipefail
63+
eval "$BENCH_CMD --compare $RUNNER_TEMP/$BASELINE_FILE" | tee "$RUNNER_TEMP/$COMPARE_OUT_FILE"
64+
- name: Upload benchmark artifacts
65+
uses: actions/upload-artifact@v4
66+
with:
67+
name: benchmark-results
68+
path: |
69+
${{ runner.temp }}/${{ env.BASELINE_FILE }}
70+
${{ runner.temp }}/${{ env.COMPARE_OUT_FILE }}

0 commit comments

Comments
 (0)