Skip to content

Replace performance tests with Benchmarks #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/benchmarks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

strategy:
matrix:
os: [ubuntu-latest]
os: [ubuntu-latest, macOS-14]

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
if: ${{ env.hasBenchmark == '1' }}
run: |
cd Benchmarks
swift package --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update pull_request
swift package --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update pull_request --filter "^(?!Foundation).*"
- name: Switch to branch 'main'
if: ${{ env.hasBenchmark == '1' }}
run: |
Expand All @@ -56,7 +56,7 @@ jobs:
if: ${{ env.hasBenchmark == '1' }}
run: |
cd Benchmarks
swift package --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update main
swift package --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update main --filter "^(?!Foundation).*"
- name: Compare PR and main
if: ${{ env.hasBenchmark == '1' }}
id: benchmark
Expand Down
25 changes: 0 additions & 25 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,6 @@ jobs:
with:
file: info.lcov

"tuxOS-Performance-Tests":
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
images:
- swift:5.10
container:
image: ${{ matrix.images }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build & run
run: swift run -c release

"macOS-Tests":
runs-on: macOS-14
strategy:
Expand All @@ -73,13 +58,3 @@ jobs:
uses: codecov/codecov-action@v4
with:
file: info.lcov

"macOS-Performance-Tests":
runs-on: macOS-13
strategy:
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build & run
run: swift run -c release
45 changes: 45 additions & 0 deletions Benchmarks/Benchmarks/BaseN/BaseN.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Benchmark
import ExtrasBase64
import Foundation

let benchmarks = {
Benchmark.defaultConfiguration = .init(
Expand Down Expand Up @@ -53,4 +54,48 @@ let benchmarks = {
try blackHole(Base64.decode(string: base64))
}
}

Benchmark("Foundation.encodeToData") { benchmark in
let bytes = Array(UInt8(0) ... UInt8(255))
let data = Data(bytes)

benchmark.startMeasurement()

for _ in benchmark.scaledIterations {
blackHole(data.base64EncodedData())
}
}

Benchmark("Foundation.encodeToString") { benchmark in
let bytes = Array(UInt8(0) ... UInt8(255))
let data = Data(bytes)

benchmark.startMeasurement()

for _ in benchmark.scaledIterations {
blackHole(data.base64EncodedString())
}
}

Benchmark("Foundation.decodeString") { benchmark in
let bytes = Array(UInt8(0) ... UInt8(255))
let base64 = Base64.encodeToString(bytes: bytes)

benchmark.startMeasurement()

for _ in benchmark.scaledIterations {
blackHole(Data(base64Encoded: base64))
}
}

Benchmark("Foundation.decodeStringIgnoreUnknownCharacters") { benchmark in
let bytes = Array(UInt8(0) ... UInt8(255))
let base64 = Base64.encodeToString(bytes: bytes)

benchmark.startMeasurement()

for _ in benchmark.scaledIterations {
blackHole(Data(base64Encoded: base64, options: .ignoreUnknownCharacters))
}
}
}
1 change: 0 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ let package = Package(
dependencies: [],
targets: [
.target(name: "ExtrasBase64", dependencies: []),
.target(name: "PerformanceTest", dependencies: ["ExtrasBase64"]),
.testTarget(name: "ExtrasBase64Tests", dependencies: ["ExtrasBase64"]),
]
)
87 changes: 0 additions & 87 deletions Sources/PerformanceTest/main.swift

This file was deleted.

Loading