Skip to content

Commit 408f524

Browse files
authored
Merge pull request #15 from heckj/main
adds sub-project with benchmarks
2 parents cb7975a + ec25890 commit 408f524

File tree

7 files changed

+301
-0
lines changed

7 files changed

+301
-0
lines changed

.github/workflows/build.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,28 @@ jobs:
1818
run: |
1919
swift --version
2020
swift build
21+
22+
benchmark-macos:
23+
runs-on: macos-14
24+
steps:
25+
- uses: actions/checkout@v3
26+
- uses: SwiftyLab/setup-swift@latest
27+
with:
28+
swift-version: "5.10.0"
29+
- name: Homebrew Mac
30+
if: ${{ runner.os == 'Macos' }}
31+
run: |
32+
echo "/opt/homebrew/bin:/usr/local/bin" >> $GITHUB_PATH
33+
brew install jemalloc
34+
- name: Ubuntu deps
35+
if: ${{ runner.os == 'Linux' }}
36+
run: |
37+
sudo apt-get install -y libjemalloc-dev
38+
- name: benchmark
39+
run: |
40+
cd ExternalBenchmarks
41+
swift package benchmark
42+
2143
build-linux:
2244
runs-on: ubuntu-22.04
2345
steps:

ExternalBenchmarks/.benchmarkBaselines/ExternalBenchmarks/bdb4ef08/results.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

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: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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(1024 * 1024) // Default = 100_000
19+
Benchmark.defaultConfiguration.maxDuration = .seconds(1) // Default = 1 second
20+
Benchmark.defaultConfiguration.metrics = [.throughput, .wallClock]
21+
22+
Benchmark("disk2d") { benchmark in
23+
var poisson = DiskSampler2D(seed: 0)
24+
for _ in benchmark.scaledIterations {
25+
blackHole(poisson.generate(radius: 10, width: viewer_size, height: viewer_size))
26+
}
27+
}
28+
29+
Benchmark("cell2d") { benchmark in
30+
for _ in benchmark.scaledIterations {
31+
blackHole(CellNoise2D(amplitude: 255, frequency: 0.01))
32+
}
33+
}
34+
35+
Benchmark("cell3d") { benchmark in
36+
for _ in benchmark.scaledIterations {
37+
blackHole(CellNoise3D(amplitude: 255, frequency: 0.01))
38+
}
39+
}
40+
41+
Benchmark("cell_tiling3d") { benchmark in
42+
for _ in benchmark.scaledIterations {
43+
blackHole(
44+
TilingCellNoise3D(amplitude: 255,
45+
frequency: 16 / Double(viewer_size),
46+
wavelengths: 16)
47+
)
48+
}
49+
}
50+
51+
Benchmark("classic_tiling_fbm3d") { benchmark in
52+
for _ in benchmark.scaledIterations {
53+
blackHole(
54+
FBM<TilingClassicNoise3D>(
55+
tiling: TilingClassicNoise3D(amplitude: 255,
56+
frequency: 16 / Double(viewer_size),
57+
wavelengths: 16),
58+
octaves: 10,
59+
persistence: 0.62)
60+
)
61+
}
62+
}
63+
64+
Benchmark("classic3d") { benchmark in
65+
for _ in benchmark.scaledIterations {
66+
blackHole(
67+
FBM<ClassicNoise3D>(ClassicNoise3D(amplitude: 255, frequency: 0.001),
68+
octaves: 10, persistence: 0.62)
69+
)
70+
}
71+
}
72+
73+
74+
Benchmark("classic_tiling3d") { benchmark in
75+
for _ in benchmark.scaledIterations {
76+
blackHole(
77+
TilingClassicNoise3D(amplitude: 255, frequency: 16 / Double(viewer_size), wavelengths: 16)
78+
)
79+
}
80+
}
81+
Benchmark("gradient2d") { benchmark in
82+
for _ in benchmark.scaledIterations {
83+
blackHole(
84+
FBM<GradientNoise2D>(GradientNoise2D(amplitude: 180, frequency: 0.001), octaves: 10, persistence: 0.62)
85+
)
86+
}
87+
}
88+
89+
Benchmark("gradient3d") { benchmark in
90+
for _ in benchmark.scaledIterations {
91+
blackHole(
92+
FBM<GradientNoise3D>(GradientNoise3D(amplitude: 180, frequency: 0.001), octaves: 10, persistence: 0.62)
93+
)
94+
}
95+
}
96+
97+
98+
99+
100+
101+
}
102+

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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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
11+
12+
## Using Benchmarks
13+
14+
- [Documentation for the package](https://swiftinit.org/docs/package-benchmark/benchmark/gettingstarted)
15+
- [Creating and Comparing Baselines](https://swiftinit.org/docs/package-benchmark/benchmark/creatingandcomparingbaselines)
16+
- [Exporting Benchmark Results](https://swiftinit.org/docs/package-benchmark/benchmark/exportingbenchmarks)
17+
18+
## Baselines
19+
20+
The baselines are set by commit hash (first 8 hex characters) or (in the future) tag with this work in place.
21+
The initial baseline is `bdb4ef08`.
22+
It builds on the tag `1.0.0` with updates to dependencies and Swift versions and no functional code changes.
23+
24+
```bash
25+
swift package --allow-writing-to-package-directory benchmark baseline update bdb4ef08
26+
```
27+
28+
To compare current development branch against this baseline, run the following command from this sub-project in the terminal:
29+
30+
```bash
31+
swift package benchmark baseline compare bdb4ef08
32+
```
33+
34+
The output defaults to plain text. If you'd like markdown output, for pasting into a pull request, add `--format markdown` to the command.
35+
36+
For a summary comparison, use the command:
37+
38+
```bash
39+
swift package benchmark baseline check --check-absolute
40+
```
41+
42+
### Stored Baselines
43+
44+
`bdb4ef08`: M1 macbook pro, 16GB ram, running only iTerm2
45+
46+

0 commit comments

Comments
 (0)