Skip to content

[benchmark] Add swiftpm support for the benchmark suite. #16977

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
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
2 changes: 1 addition & 1 deletion benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ set(SWIFT_MULTISOURCE_SWIFT3_BENCHES

set(PrimsSplit_sources
multi-source/PrimsSplit/Prims.swift
multi-source/PrimsSplit/main.swift)
multi-source/PrimsSplit/Prims_main.swift)

set(SWIFT_MULTISOURCE_SWIFT4_BENCHES
)
Expand Down
88 changes: 88 additions & 0 deletions benchmark/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// swift-tools-version:4.0

import PackageDescription
import Foundation

// This is a stop gap hack so we can edit benchmarks in Xcode.
let singleSourceLibraries: [String] = {
let f = FileManager.`default`
let dirURL = URL(fileURLWithPath: "single-source").absoluteURL
let fileURLs = try! f.contentsOfDirectory(at: dirURL,
includingPropertiesForKeys: nil)
return fileURLs.flatMap { (path: URL) -> String? in
let c = path.lastPathComponent.split(separator: ".")
// Too many components. Must be a gyb file.
if c.count > 2 {
return nil
}
if c[1] != "swift" {
return nil
}

// We do not support this test.
if c[0] == "ObjectiveCNoBridgingStubs" {
return nil
}

assert(c[0] != "PrimsSplit")
return String(c[0])
}
}()

let multiSourceLibraries: [String] = {
let f = FileManager.`default`
let dirURL = URL(fileURLWithPath: "multi-source").absoluteURL
let fileURLs = try! f.contentsOfDirectory(at: dirURL,
includingPropertiesForKeys: nil)
return fileURLs.map { (path: URL) -> String in
return path.lastPathComponent
}
}()

let p = Package(
name: "swiftbench",
products: [
.library(name: "TestsUtils", type: .static, targets: ["TestsUtils"]),
.library(name: "DriverUtils", type: .static, targets: ["DriverUtils"]),
.library(name: "ObjectiveCTests", type: .static, targets: ["ObjectiveCTests"]),
.executable(name: "SwiftBench", targets: ["SwiftBench"]),
.library(name: "PrimsSplit", type: .static, targets: ["PrimsSplit"])
] + singleSourceLibraries.map { .library(name: $0, type: .static, targets: [$0]) }
+ multiSourceLibraries.map { .library(name: $0, type: .static, targets: [$0]) },
targets: [
.target(name: "TestsUtils",
path: "utils",
sources: ["TestsUtils.swift"]),
.target(name: "DriverUtils",
dependencies: [.target(name: "TestsUtils")],
path: "utils",
sources: ["DriverUtils.swift", "ArgParse.swift"]),
.target(name: "SwiftBench",
dependencies: [
.target(name: "TestsUtils"),
.target(name: "ObjectiveCTests"),
.target(name: "DriverUtils"),
] + singleSourceLibraries.map { .target(name: $0) }
+ multiSourceLibraries.map { .target(name: $0) },
path: "utils",
sources: ["main.swift"]),
.target(name: "ObjectiveCTests",
path: "utils/ObjectiveCTests",
publicHeadersPath: "."),
] + singleSourceLibraries.map { x in
return .target(name: x,
dependencies: [
.target(name: "TestsUtils"),
.target(name: "ObjectiveCTests"),
],
path: "single-source",
sources: ["\(x).swift"])
} + multiSourceLibraries.map { x in
return .target(name: x,
dependencies: [
.target(name: "TestsUtils")
],
path: "multi-source/\(x)")
},
swiftLanguageVersions: [4]
)
4 changes: 4 additions & 0 deletions benchmark/utils/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ import NopDeinit
import ObjectAllocation
import ObjectiveCBridging
import ObjectiveCBridgingStubs
#if !SWIFT_PACKAGE
import ObjectiveCNoBridgingStubs
#endif
import ObserverClosure
import ObserverForwarderStruct
import ObserverPartiallyAppliedMethod
Expand Down Expand Up @@ -252,7 +254,9 @@ registerBenchmark(NopDeinit)
registerBenchmark(ObjectAllocation)
registerBenchmark(ObjectiveCBridging)
registerBenchmark(ObjectiveCBridgingStubs)
#if !SWIFT_PACKAGE
registerBenchmark(ObjectiveCNoBridgingStubs)
#endif
registerBenchmark(ObserverClosure)
registerBenchmark(ObserverForwarderStruct)
registerBenchmark(ObserverPartiallyAppliedMethod)
Expand Down