Skip to content

Commit c270645

Browse files
authored
Replace performance tests with Benchmarks (#35)
* 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
1 parent 4ce194f commit c270645

File tree

5 files changed

+48
-116
lines changed

5 files changed

+48
-116
lines changed

Diff for: .github/workflows/benchmarks.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
strategy:
2020
matrix:
21-
os: [ubuntu-latest]
21+
os: [ubuntu-latest, macOS-14]
2222

2323
steps:
2424
- uses: actions/checkout@v4
@@ -46,7 +46,7 @@ jobs:
4646
if: ${{ env.hasBenchmark == '1' }}
4747
run: |
4848
cd Benchmarks
49-
swift package --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update pull_request
49+
swift package --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update pull_request --filter "^(?!Foundation).*"
5050
- name: Switch to branch 'main'
5151
if: ${{ env.hasBenchmark == '1' }}
5252
run: |
@@ -56,7 +56,7 @@ jobs:
5656
if: ${{ env.hasBenchmark == '1' }}
5757
run: |
5858
cd Benchmarks
59-
swift package --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update main
59+
swift package --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update main --filter "^(?!Foundation).*"
6060
- name: Compare PR and main
6161
if: ${{ env.hasBenchmark == '1' }}
6262
id: benchmark

Diff for: .github/workflows/ci.yaml

-25
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,6 @@ jobs:
4343
with:
4444
file: info.lcov
4545

46-
"tuxOS-Performance-Tests":
47-
runs-on: ubuntu-latest
48-
strategy:
49-
fail-fast: false
50-
matrix:
51-
images:
52-
- swift:5.10
53-
container:
54-
image: ${{ matrix.images }}
55-
steps:
56-
- name: Checkout
57-
uses: actions/checkout@v4
58-
- name: Build & run
59-
run: swift run -c release
60-
6146
"macOS-Tests":
6247
runs-on: macOS-14
6348
strategy:
@@ -73,13 +58,3 @@ jobs:
7358
uses: codecov/codecov-action@v4
7459
with:
7560
file: info.lcov
76-
77-
"macOS-Performance-Tests":
78-
runs-on: macOS-13
79-
strategy:
80-
fail-fast: false
81-
steps:
82-
- name: Checkout
83-
uses: actions/checkout@v4
84-
- name: Build & run
85-
run: swift run -c release

Diff for: Benchmarks/Benchmarks/BaseN/BaseN.swift

+45
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Benchmark
22
import ExtrasBase64
3+
import Foundation
34

45
let benchmarks = {
56
Benchmark.defaultConfiguration = .init(
@@ -53,4 +54,48 @@ let benchmarks = {
5354
try blackHole(Base64.decode(string: base64))
5455
}
5556
}
57+
58+
Benchmark("Foundation.encodeToData") { benchmark in
59+
let bytes = Array(UInt8(0) ... UInt8(255))
60+
let data = Data(bytes)
61+
62+
benchmark.startMeasurement()
63+
64+
for _ in benchmark.scaledIterations {
65+
blackHole(data.base64EncodedData())
66+
}
67+
}
68+
69+
Benchmark("Foundation.encodeToString") { benchmark in
70+
let bytes = Array(UInt8(0) ... UInt8(255))
71+
let data = Data(bytes)
72+
73+
benchmark.startMeasurement()
74+
75+
for _ in benchmark.scaledIterations {
76+
blackHole(data.base64EncodedString())
77+
}
78+
}
79+
80+
Benchmark("Foundation.decodeString") { benchmark in
81+
let bytes = Array(UInt8(0) ... UInt8(255))
82+
let base64 = Base64.encodeToString(bytes: bytes)
83+
84+
benchmark.startMeasurement()
85+
86+
for _ in benchmark.scaledIterations {
87+
blackHole(Data(base64Encoded: base64))
88+
}
89+
}
90+
91+
Benchmark("Foundation.decodeStringIgnoreUnknownCharacters") { benchmark in
92+
let bytes = Array(UInt8(0) ... UInt8(255))
93+
let base64 = Base64.encodeToString(bytes: bytes)
94+
95+
benchmark.startMeasurement()
96+
97+
for _ in benchmark.scaledIterations {
98+
blackHole(Data(base64Encoded: base64, options: .ignoreUnknownCharacters))
99+
}
100+
}
56101
}

Diff for: Package.swift

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ let package = Package(
1111
dependencies: [],
1212
targets: [
1313
.target(name: "ExtrasBase64", dependencies: []),
14-
.target(name: "PerformanceTest", dependencies: ["ExtrasBase64"]),
1514
.testTarget(name: "ExtrasBase64Tests", dependencies: ["ExtrasBase64"]),
1615
]
1716
)

Diff for: Sources/PerformanceTest/main.swift

-87
This file was deleted.

0 commit comments

Comments
 (0)