Skip to content

Commit 7921e8c

Browse files
authored
Merge pull request #16977 from gottesmm/pr-968b0144efee999037465a3d20b909b231109ecc
[benchmark] Add swiftpm support for the benchmark suite.
2 parents 84530ad + 0a70ec3 commit 7921e8c

File tree

4 files changed

+93
-1
lines changed

4 files changed

+93
-1
lines changed

benchmark/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ set(SWIFT_MULTISOURCE_SWIFT3_BENCHES
173173

174174
set(PrimsSplit_sources
175175
multi-source/PrimsSplit/Prims.swift
176-
multi-source/PrimsSplit/main.swift)
176+
multi-source/PrimsSplit/Prims_main.swift)
177177

178178
set(SWIFT_MULTISOURCE_SWIFT4_BENCHES
179179
)

benchmark/Package.swift

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// swift-tools-version:4.0
2+
3+
import PackageDescription
4+
import Foundation
5+
6+
// This is a stop gap hack so we can edit benchmarks in Xcode.
7+
let singleSourceLibraries: [String] = {
8+
let f = FileManager.`default`
9+
let dirURL = URL(fileURLWithPath: "single-source").absoluteURL
10+
let fileURLs = try! f.contentsOfDirectory(at: dirURL,
11+
includingPropertiesForKeys: nil)
12+
return fileURLs.flatMap { (path: URL) -> String? in
13+
let c = path.lastPathComponent.split(separator: ".")
14+
// Too many components. Must be a gyb file.
15+
if c.count > 2 {
16+
return nil
17+
}
18+
if c[1] != "swift" {
19+
return nil
20+
}
21+
22+
// We do not support this test.
23+
if c[0] == "ObjectiveCNoBridgingStubs" {
24+
return nil
25+
}
26+
27+
assert(c[0] != "PrimsSplit")
28+
return String(c[0])
29+
}
30+
}()
31+
32+
let multiSourceLibraries: [String] = {
33+
let f = FileManager.`default`
34+
let dirURL = URL(fileURLWithPath: "multi-source").absoluteURL
35+
let fileURLs = try! f.contentsOfDirectory(at: dirURL,
36+
includingPropertiesForKeys: nil)
37+
return fileURLs.map { (path: URL) -> String in
38+
return path.lastPathComponent
39+
}
40+
}()
41+
42+
let p = Package(
43+
name: "swiftbench",
44+
products: [
45+
.library(name: "TestsUtils", type: .static, targets: ["TestsUtils"]),
46+
.library(name: "DriverUtils", type: .static, targets: ["DriverUtils"]),
47+
.library(name: "ObjectiveCTests", type: .static, targets: ["ObjectiveCTests"]),
48+
.executable(name: "SwiftBench", targets: ["SwiftBench"]),
49+
.library(name: "PrimsSplit", type: .static, targets: ["PrimsSplit"])
50+
] + singleSourceLibraries.map { .library(name: $0, type: .static, targets: [$0]) }
51+
+ multiSourceLibraries.map { .library(name: $0, type: .static, targets: [$0]) },
52+
targets: [
53+
.target(name: "TestsUtils",
54+
path: "utils",
55+
sources: ["TestsUtils.swift"]),
56+
.target(name: "DriverUtils",
57+
dependencies: [.target(name: "TestsUtils")],
58+
path: "utils",
59+
sources: ["DriverUtils.swift", "ArgParse.swift"]),
60+
.target(name: "SwiftBench",
61+
dependencies: [
62+
.target(name: "TestsUtils"),
63+
.target(name: "ObjectiveCTests"),
64+
.target(name: "DriverUtils"),
65+
] + singleSourceLibraries.map { .target(name: $0) }
66+
+ multiSourceLibraries.map { .target(name: $0) },
67+
path: "utils",
68+
sources: ["main.swift"]),
69+
.target(name: "ObjectiveCTests",
70+
path: "utils/ObjectiveCTests",
71+
publicHeadersPath: "."),
72+
] + singleSourceLibraries.map { x in
73+
return .target(name: x,
74+
dependencies: [
75+
.target(name: "TestsUtils"),
76+
.target(name: "ObjectiveCTests"),
77+
],
78+
path: "single-source",
79+
sources: ["\(x).swift"])
80+
} + multiSourceLibraries.map { x in
81+
return .target(name: x,
82+
dependencies: [
83+
.target(name: "TestsUtils")
84+
],
85+
path: "multi-source/\(x)")
86+
},
87+
swiftLanguageVersions: [4]
88+
)

benchmark/utils/main.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ import NopDeinit
9292
import ObjectAllocation
9393
import ObjectiveCBridging
9494
import ObjectiveCBridgingStubs
95+
#if !SWIFT_PACKAGE
9596
import ObjectiveCNoBridgingStubs
97+
#endif
9698
import ObserverClosure
9799
import ObserverForwarderStruct
98100
import ObserverPartiallyAppliedMethod
@@ -252,7 +254,9 @@ registerBenchmark(NopDeinit)
252254
registerBenchmark(ObjectAllocation)
253255
registerBenchmark(ObjectiveCBridging)
254256
registerBenchmark(ObjectiveCBridgingStubs)
257+
#if !SWIFT_PACKAGE
255258
registerBenchmark(ObjectiveCNoBridgingStubs)
259+
#endif
256260
registerBenchmark(ObserverClosure)
257261
registerBenchmark(ObserverForwarderStruct)
258262
registerBenchmark(ObserverPartiallyAppliedMethod)

0 commit comments

Comments
 (0)