Skip to content

Commit 89b97d3

Browse files
committed
Add benchmark job in CI
1 parent 157f03c commit 89b97d3

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

.github/workflows/pull_request.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,61 @@ 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_FILE: benchmark-pr
30+
COMPARE_OUT_FILE: benchmark-results.txt
31+
steps:
32+
- name: Check out baseline branch
33+
uses: actions/checkout@v4
34+
with:
35+
ref: ${{ github.event.pull_request.base.sha }}
36+
path: base
37+
fetch-depth: 0
38+
- name: Build baseline branch
39+
working-directory: base
40+
run: |
41+
set -euo pipefail
42+
eval "$BUILD_CMD"
43+
- name: Run baseline benchmark
44+
working-directory: base
45+
run: |
46+
set -euo pipefail
47+
eval "$BENCH_CMD --save $RUNNER_TEMP/$BASELINE_FILE"
48+
test -s "$RUNNER_TEMP/$BASELINE_FILE" || { echo "Baseline not created at $BASELINE_FILE"; exit 1; }
49+
- name: Check out PR branch
50+
uses: actions/checkout@v4
51+
with:
52+
ref: ${{ github.event.pull_request.head.sha }}
53+
path: pr
54+
fetch-depth: 0
55+
- name: Build PR branch
56+
working-directory: pr
57+
run: |
58+
set -euo pipefail
59+
eval "$BUILD_CMD"
60+
- name: Run PR benchmark
61+
working-directory: pr
62+
run: |
63+
set -euo pipefail
64+
eval "$BENCH_CMD --save $RUNNER_TEMP/$COMPARE_FILE"
65+
test -s "$RUNNER_TEMP/$COMPARE_FILE" || { echo "Comparison not created at $COMPARE_FILE"; exit 1; }
66+
eval "$BENCH_CMD --compare $RUNNER_TEMP/$BASELINE_FILE" | tee "$RUNNER_TEMP/$COMPARE_OUT_FILE"
67+
- name: Compare benchmarks
68+
working-directory: pr
69+
run: |
70+
set -euo pipefail
71+
eval "$BENCH_CMD --load $RUNNER_TEMP/$COMPARE_FILE --compare $RUNNER_TEMP/$BASELINE_FILE " | tee "$RUNNER_TEMP/$COMPARE_OUT_FILE"
72+
- name: Upload benchmark artifacts
73+
uses: actions/upload-artifact@v4
74+
with:
75+
name: benchmark-results
76+
path: |
77+
${{ runner.temp }}/${{ env.BASELINE_FILE }}
78+
${{ runner.temp }}/${{ env.COMPARE_FILE }}
79+
${{ runner.temp }}/${{ env.COMPARE_OUT_FILE }}

Sources/RegexBenchmark/Utils/Stats.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ enum Stats {}
1515

1616
extension Stats {
1717
// Maximum allowed standard deviation is 7.5% of the median runtime
18-
static let maxAllowedStdev = 0.075
18+
static let maxAllowedStdev = 0.15
1919

2020
static func tTest(_ a: Measurement, _ b: Measurement) -> Bool {
2121
// Student's t-test

0 commit comments

Comments
 (0)