Skip to content

Commit 8daf174

Browse files
hassilaordo-ci
andauthored
fix(minor): Make setup/teardown hooks usable in Swift 6 mode (#312)
Fixes #311 --------- Co-authored-by: ordo-ci <[email protected]>
1 parent 2bb8a39 commit 8daf174

28 files changed

+194
-235
lines changed

.github/workflows/swift-linux-previous.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
os: [ubuntu-latest]
16+
os: [ubuntu-22.04]
1717
swift: ["5.9", "5.10"]
1818

1919

.github/workflows/swift-macos-previous.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
os: [macos-14]
17-
swift: ["5.9", "5.10"]
17+
xcode: ["15.2", "15.3"]
18+
#swift: ["5.9", "5.10"]
1819

1920
runs-on: ${{ matrix.os }}
2021

2122
steps:
2223
- uses: swift-actions/setup-swift@v2
24+
if: ${{ false }}
2325
with:
2426
swift-version: ${{ matrix.swift }}
27+
- uses: maxim-lobanov/setup-xcode@v1
28+
with:
29+
xcode-version: ${{ matrix.xcode }}
2530

2631
- name: Homebrew Mac
2732
if: ${{ runner.os == 'Macos' }}
@@ -49,3 +54,6 @@ jobs:
4954
if [ -d Tests ]; then
5055
swift test -c release --parallel
5156
fi
57+
- name: Setup tmate session
58+
if: failure()
59+
uses: mxschmitt/action-tmate@v3

Benchmarks/Benchmarks/Basic/Basic+SetupTeardown.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ func sharedTeardown() {
1818
}
1919

2020
func testSetUpTearDown() {
21-
// Benchmark.setup = { print("Global setup hook")}
21+
// Benchmark.setup = { print("Global setup hook")}
2222
// Benchmark.setup = { 123 }
23-
// Benchmark.teardown = { print("Global teardown hook") }
23+
// Benchmark.teardown = { print("Global teardown hook") }
2424

2525
Benchmark("SetupTeardown",
2626
configuration: .init(setup: sharedSetup, teardown: sharedTeardown)) { _ in

Benchmarks/Benchmarks/Basic/BenchmarkRunner+Basic.swift

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,10 @@ import Glibc
2121
// quiet swiftlint for now
2222
extension BenchmarkRunner {}
2323

24-
let benchmarks = {
24+
let benchmarks: @Sendable () -> Void = {
2525
var thresholdTolerances: [BenchmarkMetric: BenchmarkThresholds]
2626

27-
if Benchmark.checkAbsoluteThresholds {
28-
let absolute: BenchmarkThresholds.AbsoluteThresholds = [.p0: .microseconds(1),
29-
.p25: .microseconds(1),
30-
.p50: .microseconds(2_500),
31-
.p75: .microseconds(1),
32-
.p90: .microseconds(2),
33-
.p99: .milliseconds(3),
34-
.p100: .milliseconds(1)]
35-
36-
thresholdTolerances = [.wallClock: .init(absolute: absolute)]
37-
} else {
38-
thresholdTolerances = [.wallClock: .relaxed]
39-
}
27+
thresholdTolerances = [.wallClock: .relaxed]
4028

4129
Benchmark.defaultConfiguration = .init(warmupIterations: 0,
4230
maxDuration: .seconds(1),

Benchmarks/Benchmarks/DateTime/DateTime.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import Benchmark
1111
import DateTime
1212

13-
let benchmarks = {
13+
let benchmarks: @Sendable () -> Void = {
1414
Benchmark.defaultConfiguration = .init(metrics: [.throughput, .wallClock, .instructions] + .arc,
1515
warmupIterations: 10,
1616
scalingFactor: .kilo,

Benchmarks/Benchmarks/Histogram/Histogram.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import Benchmark
1111
import Histogram
1212

13-
let benchmarks = {
13+
let benchmarks: @Sendable () -> Void = {
1414
let metrics: [BenchmarkMetric] = [
1515
.wallClock,
1616
.throughput,

Benchmarks/Benchmarks/P90AbsoluteThresholds/P90AbsoluteThresholds.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Foundation
1818
#error("Unsupported Platform")
1919
#endif
2020

21-
let benchmarks = {
21+
let benchmarks: @Sendable () -> Void = {
2222
var thresholdTolerances: [BenchmarkMetric: BenchmarkThresholds]
2323
let relative: BenchmarkThresholds.RelativeThresholds = [.p25: 25.0, .p50: 50.0, .p75: 75.0, .p90: 100.0, .p99: 101.0, .p100: 201.0]
2424
let absolute: BenchmarkThresholds.AbsoluteThresholds = [.p75: 999, .p90: 1_000, .p99: 1_001, .p100: 2_001]

Benchmarks/Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.9
1+
// swift-tools-version: 6.0
22

33
import class Foundation.ProcessInfo
44
import PackageDescription
@@ -8,7 +8,7 @@ let disableJemalloc = ProcessInfo.processInfo.environment["BENCHMARK_DISABLE_JEM
88

99
let package = Package(
1010
name: "Benchmarks",
11-
platforms: [.macOS(.v14), .iOS(.v17)],
11+
platforms: [.macOS(.v15), .iOS(.v17)],
1212
dependencies: [
1313
.package(path: "../"),
1414
.package(url: "https://github.com/ordo-one/package-datetime", .upToNextMajor(from: "1.0.1")),

Plugins/BenchmarkCommandPlugin/Command+Helpers.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ public enum Grouping: String, CaseIterable {
5151
case benchmark
5252
}
5353

54-
#if swift(>=5.8)
5554
@_documentation(visibility: internal)
56-
#endif
5755
public enum TimeUnits: String, CaseIterable {
5856
case nanoseconds
5957
case microseconds

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ There are [documentation available](https://swiftpackageindex.com/ordo-one/packa
9292
```swift
9393
import Benchmark
9494

95-
let benchmarks = {
95+
let benchmarks : @Sendable () -> Void = {
9696
Benchmark("Minimal benchmark") { benchmark in
9797
// measure something here
9898
}
@@ -159,6 +159,14 @@ Using [jmh.morethan.io](https://jmh.morethan.io)
159159

160160
<img width="1482" alt="image" src="https://user-images.githubusercontent.com/8501048/225313559-33014755-797f-4ddf-b536-24c1a618f271.png">
161161

162+
## Swift 6 support
163+
The package supports Swift 6.0 benchmark targets as well as Swift 5.10 targets (for Swift 5.9 support, need to use version 1.28.0 exactly).
164+
165+
For Swift 6 targets, use the following signature for the benchmarks closure:
166+
```swift
167+
let benchmarks : @Sendable () -> Void = {
168+
```
169+
162170
## Output
163171

164172
The default text output from Benchmark is oriented around [the five-number summary](https://en.wikipedia.org/wiki/Five-number_summary) percentiles, plus the last decile (`p90`) and the last percentile (`p99`) - it's thus a variation of a [seven-figure summary](https://en.wikipedia.org/wiki/Seven-number_summary) with the focus on the 'bad' end of results (as those are what we typically care about addressing).
@@ -168,16 +176,6 @@ This multi-modal nature of the latency measurements leads to the common statisti
168176

169177
Please see the [documentation for further details on percentiles](https://swiftpackageindex.com/ordo-one/package-benchmark/documentation/benchmark/aboutpercentiles).
170178

171-
## Swift 6 support
172-
The package will be updated to be fully Swift 6 when 5.x support is dropped (planned to be when Swift 6.2 is released).
173-
174-
Workaround needed for Swift 6 targets, use the following signature for the benchmarks closure:
175-
```swift
176-
let benchmarks : @Sendable () -> Void = {
177-
```
178-
179-
See https://github.com/ordo-one/package-benchmark/issues/258 for more details.
180-
181179
## API and file format stability
182180
The API will be deemed stable as of `1.0.0` and follows semantical versioning for future releases.
183181

0 commit comments

Comments
 (0)