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