Skip to content

Commit b098cda

Browse files
committed
stub in sub-project benchmark with a single benchmark
1 parent a945f85 commit b098cda

File tree

5 files changed

+168
-0
lines changed

5 files changed

+168
-0
lines changed

ExternalBenchmarks/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
xcuserdata/
6+
DerivedData/
7+
.swiftpm/config/registries.json
8+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
9+
.netrc
10+
.vscode
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Benchmark
2+
import Noise
3+
import Foundation
4+
5+
let viewer_size: Int = 1024
6+
let offset: Double = 0
7+
8+
// running at roughly 500ms for a pass, so maxDuration will limit far before iteration count for this
9+
func cell2d() async -> Data {
10+
var pixbuf:[UInt8] = [UInt8](repeating: 0, count: viewer_size * viewer_size)
11+
for (i, (x, y)) in Domain2D(samples_x: viewer_size, samples_y: viewer_size).enumerated() {
12+
pixbuf[i] = UInt8(max(0, min(255, CellNoise2D(amplitude: 255, frequency: 0.01).evaluate(x, y) + offset)))
13+
}
14+
return Data(pixbuf)
15+
}
16+
17+
let benchmarks = {
18+
Benchmark.defaultConfiguration.maxIterations = .count(100_000) // same as default
19+
Benchmark.defaultConfiguration.maxDuration = .seconds(5)
20+
Benchmark.defaultConfiguration.metrics = [.throughput, .wallClock]
21+
22+
Benchmark("cell2d") { benchmark in
23+
for _ in benchmark.scaledIterations {
24+
blackHole(await cell2d())
25+
}
26+
}
27+
}
28+

ExternalBenchmarks/Package.resolved

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ExternalBenchmarks/Package.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// swift-tools-version: 5.9
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "ExternalBenchmarks",
7+
platforms: [
8+
.macOS(.v13),
9+
],
10+
dependencies: [
11+
.package(url: "https://github.com/ordo-one/package-benchmark", .upToNextMajor(from: "1.0.0")),
12+
.package(path: "../"),
13+
],
14+
targets: [
15+
.executableTarget(
16+
name: "ExternalBenchmarks",
17+
dependencies: [
18+
.product(name: "Benchmark", package: "package-benchmark"),
19+
.product(name: "BenchmarkPlugin", package: "package-benchmark"),
20+
.product(name: "Noise", package: "swift-noise"),
21+
],
22+
path: "Benchmarks/ExternalBenchmarks"
23+
)
24+
]
25+
)

ExternalBenchmarks/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# ExternalBenchmarks
2+
3+
Additional benchmarks that utilize https://github.com/ordo-one/package-benchmark.
4+
5+
This code is explicitly in a subdirectory with a local reference to swift-noise
6+
in order avoid adding transitive dependencies.
7+
8+
To run the benchmarks, invoke the following command:
9+
10+
swift package benchmark

0 commit comments

Comments
 (0)