Skip to content

Commit 57d4e04

Browse files
authored
Benchmarks: add PackageGraphBenchmarks target (#7283)
This adds a dependency on the [`package-benchmark`](https://github.com/ordo-one/package-benchmark) library, isolated to the new `Benchmarks` folder. Thus it doesn't touch CMake or self-hosted builds, and one can only pull the library if they run `swift package benchmark` in the `Benchmarks` directory. A single benchmark is added that loads SwiftPM's `Package.swift` and builds a package graph for it.
1 parent 8ec22d7 commit 57d4e04

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Basics
2+
import Benchmark
3+
import PackageModel
4+
import Workspace
5+
6+
let benchmarks = {
7+
Benchmark(
8+
"Package graph loading",
9+
configuration: .init(
10+
metrics: BenchmarkMetric.all,
11+
maxDuration: .seconds(10)
12+
)
13+
) { benchmark in
14+
let path = try AbsolutePath(validating: #file).parentDirectory.parentDirectory.parentDirectory
15+
let workspace = try Workspace(fileSystem: localFileSystem, location: .init(forRootPackage: path, fileSystem: localFileSystem))
16+
let system = ObservabilitySystem { _, _ in }
17+
18+
for _ in benchmark.scaledIterations {
19+
try workspace.loadPackageGraph(rootPath: path, observabilityScope: system.topScope)
20+
}
21+
}
22+
}

Benchmarks/Package.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// swift-tools-version: 5.7
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// This source file is part of the Swift open source project
5+
//
6+
// Copyright (c) 2023 Apple Inc. and the Swift project authors
7+
// Licensed under Apache License v2.0 with Runtime Library Exception
8+
//
9+
// See http://swift.org/LICENSE.txt for license information
10+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
import PackageDescription
15+
16+
let package = Package(
17+
name: "SwiftPMBenchmarks",
18+
platforms: [
19+
.macOS("14"),
20+
],
21+
dependencies: [
22+
.package(path: "../"),
23+
.package(url: "https://github.com/ordo-one/package-benchmark.git", from: "1.13.0"),
24+
],
25+
targets: [
26+
.executableTarget(
27+
name: "PackageGraphBenchmarks",
28+
dependencies: [
29+
.product(name: "Benchmark", package: "package-benchmark"),
30+
.product(name: "SwiftPMDataModel", package: "SwiftPM"),
31+
],
32+
path: "Benchmarks/PackageGraphBenchmarks",
33+
plugins: [
34+
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
35+
]
36+
),
37+
]
38+
)

0 commit comments

Comments
 (0)