@@ -14,43 +14,71 @@ import Foundation
14
14
import TestsUtils
15
15
16
16
let size = 200
17
+ let increasingIndexPath = indexPath ( size)
18
+ let decreasingIndexPath = indexPath ( size, reversed: true )
19
+ let increasingMaxMiddleIndexPath = indexPath ( size, middle: size + 1 )
20
+ let increasingMinMiddleIndexPath = indexPath ( size, middle: - 1 )
17
21
let tags : [ BenchmarkCategory ] = [ . validation, . api, . IndexPath]
18
22
19
23
public let IndexPathTest = [
20
24
BenchmarkInfo (
21
25
name: " IndexPath.Subscript.Mutation " ,
22
- runFunction: { n in run_IndexPathSubscriptMutation ( n * 60 , size) } ,
23
- tags: tags) ,
26
+ runFunction: { n in
27
+ run_IndexPathSubscriptMutation ( n * 10 , size, increasingIndexPath)
28
+ } ,
29
+ tags: tags,
30
+ setUpFunction: { blackHole ( increasingIndexPath) } ) ,
24
31
BenchmarkInfo (
25
32
name: " IndexPath.Subscript.Range.Mutation " ,
26
- runFunction: { n in run_IndexPathSubscriptRangeMutation ( n * 60 , size) } ,
27
- tags: tags) ,
33
+ runFunction: { n in
34
+ run_IndexPathSubscriptRangeMutation ( n, size, increasingIndexPath)
35
+ } ,
36
+ tags: tags,
37
+ setUpFunction: { blackHole ( increasingIndexPath) } ) ,
28
38
29
39
BenchmarkInfo (
30
40
name: " IndexPath.Max.Beginning " ,
31
- runFunction: { n in run_IndexPathMaxBeginning ( n * 60 ) } ,
32
- tags: tags) ,
41
+ runFunction: { n in
42
+ run_IndexPathMaxBeginning ( n * 25 , decreasingIndexPath)
43
+ } ,
44
+ tags: tags,
45
+ setUpFunction: { blackHole ( decreasingIndexPath) } ) ,
33
46
BenchmarkInfo (
34
47
name: " IndexPath.Max.Middle " ,
35
- runFunction: { n in run_IndexPathMaxMiddle ( n * 60 ) } ,
36
- tags: tags) ,
48
+ runFunction: { n in
49
+ run_IndexPathMaxMiddle ( n * 25 , increasingMaxMiddleIndexPath)
50
+ } ,
51
+ tags: tags,
52
+ setUpFunction: { blackHole ( increasingMaxMiddleIndexPath) } ) ,
37
53
BenchmarkInfo (
38
54
name: " IndexPath.Max.End " ,
39
- runFunction: { n in run_IndexPathMaxEnd ( n * 60 ) } ,
40
- tags: tags) ,
55
+ runFunction: { n in
56
+ run_IndexPathMaxEnd ( n * 25 , increasingIndexPath)
57
+ } ,
58
+ tags: tags,
59
+ setUpFunction: { blackHole ( increasingIndexPath) } ) ,
41
60
42
61
BenchmarkInfo (
43
62
name: " IndexPath.Min.Beginning " ,
44
- runFunction: { n in run_IndexPathMinBeginning ( n * 60 ) } ,
45
- tags: tags) ,
63
+ runFunction: { n in
64
+ run_IndexPathMinBeginning ( n * 25 , increasingIndexPath)
65
+ } ,
66
+ tags: tags,
67
+ setUpFunction: { blackHole ( increasingIndexPath) } ) ,
46
68
BenchmarkInfo (
47
69
name: " IndexPath.Min.Middle " ,
48
- runFunction: { n in run_IndexPathMinMiddle ( n * 60 ) } ,
49
- tags: tags) ,
70
+ runFunction: { n in
71
+ run_IndexPathMinMiddle ( n * 25 , increasingMinMiddleIndexPath)
72
+ } ,
73
+ tags: tags,
74
+ setUpFunction: { blackHole ( increasingMinMiddleIndexPath) } ) ,
50
75
BenchmarkInfo (
51
76
name: " IndexPath.Min.End " ,
52
- runFunction: { n in run_IndexPathMinEnd ( n * 60 ) } ,
53
- tags: tags) ,
77
+ runFunction: { n in
78
+ run_IndexPathMinEnd ( n * 25 , decreasingIndexPath)
79
+ } ,
80
+ tags: tags,
81
+ setUpFunction: { blackHole ( decreasingIndexPath) } ) ,
54
82
]
55
83
56
84
@inline ( __always)
@@ -72,30 +100,34 @@ func indexPath(_ size: Int, middle: Int) -> IndexPath {
72
100
func subscriptMutation(
73
101
n: Int ,
74
102
mutations: Int ,
103
+ indexPath: IndexPath ,
75
104
mutate: ( inout IndexPath , Int ) -> Void
76
105
) {
77
106
for _ in 0 ..< n {
78
- var ip = indexPath ( size)
79
107
for i in 0 ..< mutations {
108
+ var ip = indexPath
80
109
mutate ( & ip, i)
81
110
}
82
- blackHole ( ip)
83
111
}
84
112
}
85
113
86
114
@inline ( never)
87
- public func run_IndexPathSubscriptMutation( _ n: Int , _ count: Int ) {
115
+ public func run_IndexPathSubscriptMutation(
116
+ _ n: Int , _ count: Int , _ indexPath: IndexPath
117
+ ) {
88
118
subscriptMutation (
89
- n: n, mutations: count,
119
+ n: n, mutations: count, indexPath : indexPath ,
90
120
mutate: { ip, i in
91
121
ip [ i % 4 ] += 1
92
122
} )
93
123
}
94
124
95
125
@inline ( never)
96
- public func run_IndexPathSubscriptRangeMutation( _ n: Int , _ count: Int ) {
126
+ public func run_IndexPathSubscriptRangeMutation(
127
+ _ n: Int , _ count: Int , _ indexPath: IndexPath
128
+ ) {
97
129
subscriptMutation (
98
- n: n, mutations: count,
130
+ n: n, mutations: count, indexPath : indexPath ,
99
131
mutate: { ip, i in
100
132
ip [ 0 ..< i] += [ i]
101
133
} )
@@ -106,11 +138,11 @@ public func run_IndexPathSubscriptRangeMutation(_ n: Int, _ count: Int) {
106
138
@inline ( __always)
107
139
func maxMin(
108
140
n: Int ,
109
- creator : ( ) -> IndexPath ,
141
+ indexPath : IndexPath ,
110
142
maxMinFunc: ( inout IndexPath ) -> Int ?
111
143
) {
112
144
for _ in 0 ..< n {
113
- var ip = creator ( )
145
+ var ip = indexPath
114
146
let found = maxMinFunc ( & ip) != nil
115
147
blackHole ( found)
116
148
}
@@ -119,36 +151,30 @@ func maxMin(
119
151
// Max
120
152
121
153
@inline ( never)
122
- public func run_IndexPathMaxBeginning( _ n: Int ) {
154
+ public func run_IndexPathMaxBeginning( _ n: Int , _ indexPath : IndexPath ) {
123
155
maxMin (
124
156
n: n,
125
- creator: {
126
- indexPath ( size, reversed: true )
127
- } ,
157
+ indexPath: indexPath,
128
158
maxMinFunc: { ip in
129
159
ip. max ( )
130
160
} )
131
161
}
132
162
133
163
@inline ( never)
134
- public func run_IndexPathMaxMiddle( _ n: Int ) {
164
+ public func run_IndexPathMaxMiddle( _ n: Int , _ indexPath : IndexPath ) {
135
165
maxMin (
136
166
n: n,
137
- creator: {
138
- indexPath ( size, middle: size + 1 )
139
- } ,
167
+ indexPath: indexPath,
140
168
maxMinFunc: { ip in
141
169
ip. max ( )
142
170
} )
143
171
}
144
172
145
173
@inline ( never)
146
- public func run_IndexPathMaxEnd( _ n: Int ) {
174
+ public func run_IndexPathMaxEnd( _ n: Int , _ indexPath : IndexPath ) {
147
175
maxMin (
148
176
n: n,
149
- creator: {
150
- indexPath ( size)
151
- } ,
177
+ indexPath: indexPath,
152
178
maxMinFunc: { ip in
153
179
ip. max ( )
154
180
} )
@@ -157,36 +183,30 @@ public func run_IndexPathMaxEnd(_ n: Int) {
157
183
// Min
158
184
159
185
@inline ( never)
160
- public func run_IndexPathMinBeginning( _ n: Int ) {
186
+ public func run_IndexPathMinBeginning( _ n: Int , _ indexPath : IndexPath ) {
161
187
maxMin (
162
188
n: n,
163
- creator: {
164
- indexPath ( size)
165
- } ,
189
+ indexPath: indexPath,
166
190
maxMinFunc: { ip in
167
191
ip. min ( )
168
192
} )
169
193
}
170
194
171
195
@inline ( never)
172
- public func run_IndexPathMinMiddle( _ n: Int ) {
196
+ public func run_IndexPathMinMiddle( _ n: Int , _ indexPath : IndexPath ) {
173
197
maxMin (
174
198
n: n,
175
- creator: {
176
- indexPath ( size, middle: - 1 )
177
- } ,
199
+ indexPath: indexPath,
178
200
maxMinFunc: { ip in
179
201
ip. min ( )
180
202
} )
181
203
}
182
204
183
205
@inline ( never)
184
- public func run_IndexPathMinEnd( _ n: Int ) {
206
+ public func run_IndexPathMinEnd( _ n: Int , _ indexPath : IndexPath ) {
185
207
maxMin (
186
208
n: n,
187
- creator: {
188
- indexPath ( size, reversed: true )
189
- } ,
209
+ indexPath: indexPath,
190
210
maxMinFunc: { ip in
191
211
ip. min ( )
192
212
} )
0 commit comments