Skip to content

Commit b1de68f

Browse files
committed
replicate benchmarks from NoiseTest main
1 parent b098cda commit b1de68f

File tree

1 file changed

+76
-10
lines changed

1 file changed

+76
-10
lines changed

ExternalBenchmarks/Benchmarks/ExternalBenchmarks/ExternalBenchmarks.swift

Lines changed: 76 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,89 @@ let viewer_size: Int = 1024
66
let offset: Double = 0
77

88
// 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-
}
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+
//}
1616

1717
let benchmarks = {
18-
Benchmark.defaultConfiguration.maxIterations = .count(100_000) // same as default
19-
Benchmark.defaultConfiguration.maxDuration = .seconds(5)
18+
Benchmark.defaultConfiguration.maxIterations = .count(1024 * 1024) // Default = 100_000
19+
Benchmark.defaultConfiguration.maxDuration = .seconds(1) // Default = 1 second
2020
Benchmark.defaultConfiguration.metrics = [.throughput, .wallClock]
2121

2222
Benchmark("cell2d") { benchmark in
2323
for _ in benchmark.scaledIterations {
24-
blackHole(await cell2d())
24+
blackHole(CellNoise2D(amplitude: 255, frequency: 0.01))
25+
}
26+
}
27+
Benchmark("cell3d") { benchmark in
28+
for _ in benchmark.scaledIterations {
29+
blackHole(CellNoise3D(amplitude: 255, frequency: 0.01))
30+
}
31+
}
32+
33+
Benchmark("cell_tiling3d") { benchmark in
34+
for _ in benchmark.scaledIterations {
35+
blackHole(
36+
TilingCellNoise3D(amplitude: 255,
37+
frequency: 16 / Double(viewer_size),
38+
wavelengths: 16)
39+
)
40+
}
41+
}
42+
43+
Benchmark("classic_tiling_fbm3d") { benchmark in
44+
for _ in benchmark.scaledIterations {
45+
blackHole(
46+
FBM<TilingClassicNoise3D>(
47+
tiling: TilingClassicNoise3D(amplitude: 255,
48+
frequency: 16 / Double(viewer_size),
49+
wavelengths: 16),
50+
octaves: 10,
51+
persistence: 0.62)
52+
)
53+
}
54+
}
55+
56+
Benchmark("classic3d") { benchmark in
57+
for _ in benchmark.scaledIterations {
58+
blackHole(
59+
FBM<ClassicNoise3D>(ClassicNoise3D(amplitude: 255, frequency: 0.001),
60+
octaves: 10, persistence: 0.62)
61+
)
2562
}
2663
}
64+
65+
66+
Benchmark("classic_tiling3d") { benchmark in
67+
for _ in benchmark.scaledIterations {
68+
blackHole(
69+
TilingClassicNoise3D(amplitude: 255, frequency: 16 / Double(viewer_size), wavelengths: 16)
70+
)
71+
}
72+
}
73+
Benchmark("gradient2d") { benchmark in
74+
for _ in benchmark.scaledIterations {
75+
blackHole(
76+
FBM<GradientNoise2D>(GradientNoise2D(amplitude: 180, frequency: 0.001), octaves: 10, persistence: 0.62)
77+
)
78+
}
79+
}
80+
81+
Benchmark("gradient3d") { benchmark in
82+
for _ in benchmark.scaledIterations {
83+
blackHole(
84+
FBM<GradientNoise3D>(GradientNoise3D(amplitude: 180, frequency: 0.001), octaves: 10, persistence: 0.62)
85+
)
86+
}
87+
}
88+
89+
90+
91+
92+
2793
}
2894

0 commit comments

Comments
 (0)