Skip to content

Commit 4cd6251

Browse files
Update benchmarks target (#3424)
* wip * benchmark update * wip * Rename Benchmarks.swift to Benchmarks.swift --------- Co-authored-by: Brandon Williams <mbrandonw@hey.com>
1 parent f043956 commit 4cd6251

File tree

18 files changed

+340
-526
lines changed

18 files changed

+340
-526
lines changed

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.DS_Store
2-
/.build
3-
/.swiftpm
2+
.build
3+
.swiftpm
44
/Packages
55
/*.swiftinterface
66
/*.xcodeproj
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import Benchmark
2+
import ComposableArchitecture
3+
4+
private func initialState(for nesting: Int) -> Feature.State {
5+
(1..<nesting).reduce(into: Feature.State()) { state, _ in state = Feature.State(child: state) }
6+
}
7+
8+
@MainActor
9+
private func rootStore(for nesting: Int) -> StoreOf<Feature> {
10+
Store(initialState: initialState(for: nesting)) { Feature() }
11+
}
12+
13+
@MainActor
14+
private func scopedStore(for nesting: Int, from root: StoreOf<Feature>? = nil) -> StoreOf<Feature> {
15+
(1..<nesting).reduce(into: root ?? rootStore(for: nesting)) { store, _ in
16+
store = store.scope(state: \.child, action: \.child.presented)!
17+
}
18+
}
19+
20+
import Foundation
21+
22+
let benchmarks = { @Sendable in
23+
Benchmark("Store.Scope") { @MainActor benchmark async in
24+
benchmark.startMeasurement()
25+
_ = scopedStore(for: 1)
26+
}
27+
28+
Benchmark("Store.Send") { @MainActor benchmark async in
29+
let store = scopedStore(for: 1)
30+
benchmark.startMeasurement()
31+
blackHole(store.send(.incrementButtonTapped))
32+
}
33+
34+
Benchmark("Store.Access") { @MainActor benchmark async in
35+
let store = scopedStore(for: 1)
36+
benchmark.startMeasurement()
37+
blackHole(store.state)
38+
}
39+
40+
Benchmark("NestedStore.Scope") { @MainActor benchmark async in
41+
benchmark.startMeasurement()
42+
_ = scopedStore(for: 10)
43+
}
44+
45+
Benchmark("NestedStore.Send") { @MainActor benchmark async in
46+
let store = scopedStore(for: 10)
47+
benchmark.startMeasurement()
48+
blackHole(store.send(.incrementButtonTapped))
49+
}
50+
51+
Benchmark("NestedStore.RootSend") { @MainActor benchmark async in
52+
let root = rootStore(for: 10)
53+
let store = scopedStore(for: 10, from: root)
54+
benchmark.startMeasurement()
55+
blackHole(root.send(.incrementButtonTapped))
56+
}
57+
58+
Benchmark("NestedStore.NestedSend(1)") { @MainActor benchmark async in
59+
let root = rootStore(for: 10)
60+
let store = scopedStore(for: 10, from: root)
61+
benchmark.startMeasurement()
62+
blackHole(root.send(.child(.presented(.incrementButtonTapped))))
63+
}
64+
65+
Benchmark("NestedStore.Access") { @MainActor benchmark async in
66+
let store = scopedStore(for: 10)
67+
benchmark.startMeasurement()
68+
blackHole(store.state)
69+
}
70+
}
71+
72+
@Reducer
73+
private struct Feature {
74+
@ObservableState
75+
struct State {
76+
var count = 0
77+
@Presents var child: Feature.State?
78+
}
79+
enum Action {
80+
indirect case child(PresentationAction<Feature.Action>)
81+
case incrementButtonTapped
82+
}
83+
var body: some ReducerOf<Self> {
84+
Reduce { state, action in
85+
switch action {
86+
case .child:
87+
return .none
88+
case .incrementButtonTapped:
89+
state.count += 1
90+
return .none
91+
}
92+
}
93+
.ifLet(\.$child, action: \.child) {
94+
Feature()
95+
}
96+
}
97+
}

Benchmarks/Package.resolved

+186
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
{
2+
"originHash" : "7b5de47cf5b3b40e488a074bdc5be354ef0ed114464cc6e2212a197aa8eb3ed7",
3+
"pins" : [
4+
{
5+
"identity" : "combine-schedulers",
6+
"kind" : "remoteSourceControl",
7+
"location" : "https://github.com/pointfreeco/combine-schedulers",
8+
"state" : {
9+
"revision" : "9fa31f4403da54855f1e2aeaeff478f4f0e40b13",
10+
"version" : "1.0.2"
11+
}
12+
},
13+
{
14+
"identity" : "hdrhistogram-swift",
15+
"kind" : "remoteSourceControl",
16+
"location" : "https://github.com/HdrHistogram/hdrhistogram-swift",
17+
"state" : {
18+
"revision" : "a69fa24d7b70421870cafa86340ece900489e17e",
19+
"version" : "0.1.2"
20+
}
21+
},
22+
{
23+
"identity" : "package-benchmark",
24+
"kind" : "remoteSourceControl",
25+
"location" : "https://github.com/ordo-one/package-benchmark",
26+
"state" : {
27+
"revision" : "75e8622faadd4a960ef93fee76893e41e4e8daf2",
28+
"version" : "1.25.0"
29+
}
30+
},
31+
{
32+
"identity" : "package-jemalloc",
33+
"kind" : "remoteSourceControl",
34+
"location" : "https://github.com/ordo-one/package-jemalloc",
35+
"state" : {
36+
"revision" : "e8a5db026963f5bfeac842d9d3f2cc8cde323b49",
37+
"version" : "1.0.0"
38+
}
39+
},
40+
{
41+
"identity" : "swift-argument-parser",
42+
"kind" : "remoteSourceControl",
43+
"location" : "https://github.com/apple/swift-argument-parser",
44+
"state" : {
45+
"revision" : "41982a3656a71c768319979febd796c6fd111d5c",
46+
"version" : "1.5.0"
47+
}
48+
},
49+
{
50+
"identity" : "swift-atomics",
51+
"kind" : "remoteSourceControl",
52+
"location" : "https://github.com/apple/swift-atomics",
53+
"state" : {
54+
"revision" : "cd142fd2f64be2100422d658e7411e39489da985",
55+
"version" : "1.2.0"
56+
}
57+
},
58+
{
59+
"identity" : "swift-case-paths",
60+
"kind" : "remoteSourceControl",
61+
"location" : "https://github.com/pointfreeco/swift-case-paths",
62+
"state" : {
63+
"revision" : "642e6aab8e03e5f992d9c83e38c5be98cfad5078",
64+
"version" : "1.5.5"
65+
}
66+
},
67+
{
68+
"identity" : "swift-clocks",
69+
"kind" : "remoteSourceControl",
70+
"location" : "https://github.com/pointfreeco/swift-clocks",
71+
"state" : {
72+
"revision" : "b9b24b69e2adda099a1fa381cda1eeec272d5b53",
73+
"version" : "1.0.5"
74+
}
75+
},
76+
{
77+
"identity" : "swift-collections",
78+
"kind" : "remoteSourceControl",
79+
"location" : "https://github.com/apple/swift-collections",
80+
"state" : {
81+
"revision" : "9bf03ff58ce34478e66aaee630e491823326fd06",
82+
"version" : "1.1.3"
83+
}
84+
},
85+
{
86+
"identity" : "swift-concurrency-extras",
87+
"kind" : "remoteSourceControl",
88+
"location" : "https://github.com/pointfreeco/swift-concurrency-extras",
89+
"state" : {
90+
"revision" : "bb5059bde9022d69ac516803f4f227d8ac967f71",
91+
"version" : "1.1.0"
92+
}
93+
},
94+
{
95+
"identity" : "swift-custom-dump",
96+
"kind" : "remoteSourceControl",
97+
"location" : "https://github.com/pointfreeco/swift-custom-dump",
98+
"state" : {
99+
"revision" : "82645ec760917961cfa08c9c0c7104a57a0fa4b1",
100+
"version" : "1.3.3"
101+
}
102+
},
103+
{
104+
"identity" : "swift-dependencies",
105+
"kind" : "remoteSourceControl",
106+
"location" : "https://github.com/pointfreeco/swift-dependencies",
107+
"state" : {
108+
"revision" : "fd1fb25b68fdb9756cd61d23dbd9e2614b340085",
109+
"version" : "1.4.0"
110+
}
111+
},
112+
{
113+
"identity" : "swift-identified-collections",
114+
"kind" : "remoteSourceControl",
115+
"location" : "https://github.com/pointfreeco/swift-identified-collections",
116+
"state" : {
117+
"revision" : "2f5ab6e091dd032b63dacbda052405756010dc3b",
118+
"version" : "1.1.0"
119+
}
120+
},
121+
{
122+
"identity" : "swift-navigation",
123+
"kind" : "remoteSourceControl",
124+
"location" : "https://github.com/pointfreeco/swift-navigation",
125+
"state" : {
126+
"revision" : "e834b3760731160d7d448509ee6a1408c8582a6b",
127+
"version" : "2.2.0"
128+
}
129+
},
130+
{
131+
"identity" : "swift-numerics",
132+
"kind" : "remoteSourceControl",
133+
"location" : "https://github.com/apple/swift-numerics",
134+
"state" : {
135+
"revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
136+
"version" : "1.0.2"
137+
}
138+
},
139+
{
140+
"identity" : "swift-perception",
141+
"kind" : "remoteSourceControl",
142+
"location" : "https://github.com/pointfreeco/swift-perception",
143+
"state" : {
144+
"revision" : "bc67aa8e461351c97282c2419153757a446ae1c9",
145+
"version" : "1.3.5"
146+
}
147+
},
148+
{
149+
"identity" : "swift-syntax",
150+
"kind" : "remoteSourceControl",
151+
"location" : "https://github.com/swiftlang/swift-syntax",
152+
"state" : {
153+
"revision" : "cb53fa1bd3219b0b23ded7dfdd3b2baff266fd25",
154+
"version" : "600.0.0"
155+
}
156+
},
157+
{
158+
"identity" : "swift-system",
159+
"kind" : "remoteSourceControl",
160+
"location" : "https://github.com/apple/swift-system",
161+
"state" : {
162+
"revision" : "d2ba781702a1d8285419c15ee62fd734a9437ff5",
163+
"version" : "1.3.2"
164+
}
165+
},
166+
{
167+
"identity" : "texttable",
168+
"kind" : "remoteSourceControl",
169+
"location" : "https://github.com/ordo-one/TextTable",
170+
"state" : {
171+
"revision" : "a27a07300cf4ae322e0079ca0a475c5583dd575f",
172+
"version" : "0.0.2"
173+
}
174+
},
175+
{
176+
"identity" : "xctest-dynamic-overlay",
177+
"kind" : "remoteSourceControl",
178+
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
179+
"state" : {
180+
"revision" : "bc2a151366f2cd0e347274544933bc2acb00c9fe",
181+
"version" : "1.4.0"
182+
}
183+
}
184+
],
185+
"version" : 3
186+
}

Benchmarks/Package.swift

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// swift-tools-version:6.0
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "benchmarks",
7+
platforms: [
8+
.macOS("14")
9+
],
10+
dependencies: [
11+
.package(path: ".."),
12+
.package(url: "https://github.com/ordo-one/package-benchmark", from: "1.4.0"),
13+
],
14+
targets: [
15+
.executableTarget(
16+
name: "swift-composable-architecture-benchmark",
17+
dependencies: [
18+
.product(name: "Benchmark", package: "package-benchmark"),
19+
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
20+
],
21+
path: "Benchmarks/swift-composable-architecture-benchmark",
22+
plugins: [
23+
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
24+
]
25+
),
26+
]
27+
)

ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved

-18
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,6 @@
99
"version" : "1.0.2"
1010
}
1111
},
12-
{
13-
"identity" : "swift-argument-parser",
14-
"kind" : "remoteSourceControl",
15-
"location" : "https://github.com/apple/swift-argument-parser",
16-
"state" : {
17-
"revision" : "41982a3656a71c768319979febd796c6fd111d5c",
18-
"version" : "1.5.0"
19-
}
20-
},
21-
{
22-
"identity" : "swift-benchmark",
23-
"kind" : "remoteSourceControl",
24-
"location" : "https://github.com/google/swift-benchmark",
25-
"state" : {
26-
"revision" : "8163295f6fe82356b0bcf8e1ab991645de17d096",
27-
"version" : "0.1.2"
28-
}
29-
},
3012
{
3113
"identity" : "swift-case-paths",
3214
"kind" : "remoteSourceControl",

Package.resolved

+2-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"originHash" : "56d9c3bb35bdc40e748375720c367811b810b36e68baa234d35a7e72bad5ff39",
23
"pins" : [
34
{
45
"identity" : "combine-schedulers",
@@ -9,24 +10,6 @@
910
"version" : "1.0.2"
1011
}
1112
},
12-
{
13-
"identity" : "swift-argument-parser",
14-
"kind" : "remoteSourceControl",
15-
"location" : "https://github.com/apple/swift-argument-parser",
16-
"state" : {
17-
"revision" : "41982a3656a71c768319979febd796c6fd111d5c",
18-
"version" : "1.5.0"
19-
}
20-
},
21-
{
22-
"identity" : "swift-benchmark",
23-
"kind" : "remoteSourceControl",
24-
"location" : "https://github.com/google/swift-benchmark",
25-
"state" : {
26-
"revision" : "8163295f6fe82356b0bcf8e1ab991645de17d096",
27-
"version" : "0.1.2"
28-
}
29-
},
3013
{
3114
"identity" : "swift-case-paths",
3215
"kind" : "remoteSourceControl",
@@ -163,5 +146,5 @@
163146
}
164147
}
165148
],
166-
"version" : 2
149+
"version" : 3
167150
}

0 commit comments

Comments
 (0)