-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace IntegrationTests with Benchmarks (#34)
- Loading branch information
1 parent
1e8b1cc
commit 4ce194f
Showing
34 changed files
with
178 additions
and
1,569 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
name: Benchmark PR vs main | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: | ||
- main | ||
paths: | ||
- '**.swift' | ||
- '**.yml' | ||
|
||
jobs: | ||
benchmark-delta: | ||
|
||
runs-on: ${{ matrix.os }} | ||
timeout-minutes: 15 | ||
continue-on-error: true | ||
|
||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Homebrew Mac | ||
if: ${{ runner.os == 'Macos' }} | ||
run: | | ||
echo "/opt/homebrew/bin:/usr/local/bin" >> $GITHUB_PATH | ||
brew install jemalloc | ||
- name: Ubuntu deps | ||
if: ${{ runner.os == 'Linux' }} | ||
run: | | ||
sudo apt-get install -y libjemalloc-dev | ||
- name: Git URL token override and misc | ||
run: | | ||
#git config --global url."https://ordo-ci:${{ secrets.CI_MACHINE_PAT }}@github.com".insteadOf "https://github.com" | ||
#/usr/bin/ordo-performance | ||
[ -d Benchmarks ] && echo "hasBenchmark=1" >> $GITHUB_ENV | ||
echo "/opt/homebrew/bin:/usr/local/bin" >> $GITHUB_PATH | ||
- name: Run benchmarks for PR branch | ||
if: ${{ env.hasBenchmark == '1' }} | ||
run: | | ||
cd Benchmarks | ||
swift package --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update pull_request | ||
- name: Switch to branch 'main' | ||
if: ${{ env.hasBenchmark == '1' }} | ||
run: | | ||
git stash | ||
git checkout main | ||
- name: Run benchmarks for branch 'main' | ||
if: ${{ env.hasBenchmark == '1' }} | ||
run: | | ||
cd Benchmarks | ||
swift package --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update main | ||
- name: Compare PR and main | ||
if: ${{ env.hasBenchmark == '1' }} | ||
id: benchmark | ||
run: | | ||
echo $(date) >> $GITHUB_STEP_SUMMARY | ||
echo "exitStatus=1" >> $GITHUB_ENV | ||
cd Benchmarks | ||
swift package benchmark baseline check main pull_request --format markdown >> $GITHUB_STEP_SUMMARY | ||
echo "exitStatus=0" >> $GITHUB_ENV | ||
continue-on-error: true | ||
- if: ${{ env.exitStatus == '0' }} | ||
name: Pull request comment text success | ||
id: prtestsuccess | ||
run: | | ||
echo 'PRTEST<<EOF' >> $GITHUB_ENV | ||
echo "[Pull request benchmark comparison [${{ matrix.os }}] with 'main' run at $(date -Iseconds)](https://github.com/swift-extras/${{ github.event.repository.name }}/actions/runs/${{ github.run_id }})" >> $GITHUB_ENV | ||
echo 'EOF' >> $GITHUB_ENV | ||
- if: ${{ env.exitStatus == '1' }} | ||
name: Pull request comment text failure | ||
id: prtestfailure | ||
run: | | ||
echo 'PRTEST<<EOF' >> $GITHUB_ENV | ||
echo "[Pull request benchmark comparison [${{ matrix.os }}] with 'main' run at $(date -Iseconds)](https://github.com/swift-extras/${{ github.event.repository.name }}/actions/runs/${{ github.run_id }})" >> $GITHUB_ENV | ||
echo "_Pull request had performance regressions_" >> $GITHUB_ENV | ||
echo 'EOF' >> $GITHUB_ENV | ||
- name: Comment PR | ||
if: ${{ env.hasBenchmark == '1' }} | ||
uses: thollander/actions-comment-pull-request@v2 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
message: ${{ env.PRTEST }} | ||
comment_includes: "Pull request benchmark comparison [${{ matrix.os }}] with" | ||
- name: Exit with correct status | ||
run: | | ||
exit ${{ env.exitStatus }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.benchmarkBaselines | ||
Package.resolved |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Benchmark | ||
import ExtrasBase64 | ||
|
||
let benchmarks = { | ||
Benchmark.defaultConfiguration = .init( | ||
metrics: [ | ||
.cpuTotal, | ||
.throughput, | ||
.mallocCountTotal, | ||
], | ||
warmupIterations: 10, | ||
scalingFactor: .kilo | ||
) | ||
|
||
Benchmark("Base32.encode") { benchmark in | ||
let bytes = Array(UInt8(0) ... UInt8(255)) | ||
|
||
benchmark.startMeasurement() | ||
|
||
for _ in benchmark.scaledIterations { | ||
blackHole(Base32.encodeToString(bytes: bytes)) | ||
} | ||
} | ||
|
||
Benchmark("Base32.decode") { benchmark in | ||
let bytes = Array(UInt8(0) ... UInt8(255)) | ||
let base32 = Base32.encodeToString(bytes: bytes) | ||
|
||
benchmark.startMeasurement() | ||
|
||
for _ in benchmark.scaledIterations { | ||
try blackHole(Base32.decode(string: base32)) | ||
} | ||
} | ||
|
||
Benchmark("Base64.encode") { benchmark in | ||
let bytes = Array(UInt8(0) ... UInt8(255)) | ||
|
||
benchmark.startMeasurement() | ||
|
||
for _ in benchmark.scaledIterations { | ||
blackHole(Base64.encodeToString(bytes: bytes)) | ||
} | ||
} | ||
|
||
Benchmark("Base64.decode") { benchmark in | ||
let bytes = Array(UInt8(0) ... UInt8(255)) | ||
let base64 = Base64.encodeToString(bytes: bytes) | ||
|
||
benchmark.startMeasurement() | ||
|
||
for _ in benchmark.scaledIterations { | ||
try blackHole(Base64.decode(string: base64)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// swift-tools-version: 5.9 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "Benchmarks", | ||
platforms: [.macOS(.v14)], | ||
dependencies: [ | ||
.package(url: "https://github.com/ordo-one/package-benchmark.git", from: "1.0.0"), | ||
.package(name: "swift-extras-base64", path: ".."), | ||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "BaseN", | ||
dependencies: [ | ||
.product(name: "ExtrasBase64", package: "swift-extras-base64"), | ||
.product(name: "Benchmark", package: "package-benchmark"), | ||
], | ||
path: "Benchmarks/BaseN", | ||
plugins: [ | ||
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"), | ||
] | ||
), | ||
] | ||
) |
Oops, something went wrong.