Skip to content

Commit 2ddee65

Browse files
mbrandonwmluisbrown
authored andcommitted
Move scope benchmarks to its own suite. (#1314)
* Move scope benchmarks to its own suite. * wip * wip (cherry picked from commit 08e119d57781ec277bbfec314a985db52b248598)
1 parent 2ad650b commit 2ddee65

File tree

2 files changed

+26
-38
lines changed

2 files changed

+26
-38
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Benchmark
2+
import ComposableArchitecture
3+
4+
let storeScopeSuite = BenchmarkSuite(name: "Store scoping") { suite in
5+
let counterReducer = Reducer<Int, Bool, Void> { state, action, _ in
6+
if action {
7+
state += 1
8+
return .none
9+
} else {
10+
state -= 1
11+
return .none
12+
}
13+
}
14+
var store = Store(initialState: 0, reducer: counterReducer, environment: ())
15+
var viewStores: [ViewStore<Int, Bool>] = [ViewStore(store)]
16+
for _ in 1...4 {
17+
store = store.scope(state: { $0 })
18+
viewStores.append(ViewStore(store))
19+
}
20+
let lastViewStore = viewStores.last!
21+
22+
suite.benchmark("Nested store") {
23+
lastViewStore.send(true)
24+
}
25+
}
Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,8 @@
11
import Benchmark
22
import ComposableArchitecture
33

4-
let counterReducer = Reducer<Int, Bool, Void> { state, action, _ in
5-
if action {
6-
state += 1
7-
} else {
8-
state = 0
9-
}
10-
return .none
11-
}
12-
13-
let store1 = Store(initialState: 0, reducer: counterReducer, environment: ())
14-
let store2 = store1.scope { $0 }
15-
let store3 = store2.scope { $0 }
16-
let store4 = store3.scope { $0 }
17-
18-
let viewStore1 = ViewStore(store1)
19-
let viewStore2 = ViewStore(store2)
20-
let viewStore3 = ViewStore(store3)
21-
let viewStore4 = ViewStore(store4)
22-
23-
benchmark("Scoping (1)") {
24-
viewStore1.send(true)
25-
}
26-
viewStore1.send(false)
27-
28-
benchmark("Scoping (2)") {
29-
viewStore2.send(true)
30-
}
31-
viewStore1.send(false)
32-
33-
benchmark("Scoping (3)") {
34-
viewStore3.send(true)
35-
}
36-
viewStore1.send(false)
37-
38-
benchmark("Scoping (4)") {
39-
viewStore4.send(true)
40-
}
41-
424
Benchmark.main([
435
defaultBenchmarkSuite,
446
effectSuite,
7+
storeScopeSuite
458
])

0 commit comments

Comments
 (0)