Skip to content

Commit

Permalink
Replace performance tests with Benchmarks (#35)
Browse files Browse the repository at this point in the history
* Replace perfomance test with Benchmarks

* Don't compare Foundation benchmarks

* Fix GH action, and fixup benchmark names

* Run benchmarks on linux and macOS, remove old performance CI
  • Loading branch information
adam-fowler authored May 14, 2024
1 parent 4ce194f commit c270645
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 116 deletions.
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.

0 comments on commit c270645

Please sign in to comment.