@@ -23,35 +23,39 @@ let tags: [BenchmarkCategory] = [.validation, .api, .IndexPath]
23
23
public let IndexPathTest = [
24
24
BenchmarkInfo (
25
25
name: " IndexPath.Subscript.Mutation " ,
26
- runFunction: { n in
27
- run_IndexPathSubscriptMutation ( n * 10 , size, increasingIndexPath)
28
- } ,
26
+ runFunction: run_IndexPathSubscriptMutation,
29
27
tags: tags,
30
28
setUpFunction: { blackHole ( increasingIndexPath) } ) ,
31
29
BenchmarkInfo (
32
30
name: " IndexPath.Subscript.Range.Mutation " ,
33
- runFunction: { n in
34
- run_IndexPathSubscriptRangeMutation ( n, size, increasingIndexPath)
35
- } ,
31
+ runFunction: run_IndexPathSubscriptRangeMutation,
36
32
tags: tags,
37
33
setUpFunction: { blackHole ( increasingIndexPath) } ) ,
38
34
BenchmarkInfo (
39
35
name: " IndexPath.Max " ,
40
- runFunction: { n in run_IndexPathMax ( n * 10 ) } ,
41
- tags: tags) ,
36
+ runFunction: run_IndexPathMax,
37
+ tags: tags,
38
+ setUpFunction: {
39
+ blackHole ( decreasingIndexPath)
40
+ blackHole ( increasingMaxMiddleIndexPath)
41
+ blackHole ( increasingIndexPath)
42
+ } ) ,
42
43
BenchmarkInfo (
43
44
name: " IndexPath.Min " ,
44
- runFunction: { n in run_IndexPathMin ( n * 10 ) } ,
45
- tags: tags) ,
45
+ runFunction: run_IndexPathMin,
46
+ tags: tags,
47
+ setUpFunction: {
48
+ blackHole ( increasingIndexPath)
49
+ blackHole ( increasingMinMiddleIndexPath)
50
+ blackHole ( decreasingIndexPath)
51
+ } ) ,
46
52
]
47
53
48
- @inline ( __always)
49
54
func indexPath( _ size: Int , reversed: Bool = false ) -> IndexPath {
50
55
let indexes = Array ( 0 ..< size)
51
56
return IndexPath ( indexes: reversed ? indexes. reversed ( ) : indexes)
52
57
}
53
58
54
- @inline ( __always)
55
59
func indexPath( _ size: Int , middle: Int ) -> IndexPath {
56
60
var indexes = Array ( 0 ..< size)
57
61
indexes. insert ( middle, at: ( indexes. count - 1 ) / 2 )
@@ -76,22 +80,18 @@ func subscriptMutation(
76
80
}
77
81
78
82
@inline ( never)
79
- public func run_IndexPathSubscriptMutation(
80
- _ n: Int , _ count: Int , _ indexPath: IndexPath
81
- ) {
83
+ public func run_IndexPathSubscriptMutation( _ n: Int ) {
82
84
subscriptMutation (
83
- n: n, mutations: count , indexPath: indexPath ,
85
+ n: n * 10 , mutations: size , indexPath: increasingIndexPath ,
84
86
mutate: { ip, i in
85
87
ip [ i % 4 ] += 1
86
88
} )
87
89
}
88
90
89
91
@inline ( never)
90
- public func run_IndexPathSubscriptRangeMutation(
91
- _ n: Int , _ count: Int , _ indexPath: IndexPath
92
- ) {
92
+ public func run_IndexPathSubscriptRangeMutation( _ n: Int ) {
93
93
subscriptMutation (
94
- n: n, mutations: count , indexPath: indexPath ,
94
+ n: n, mutations: size , indexPath: increasingIndexPath ,
95
95
mutate: { ip, i in
96
96
ip [ 0 ..< i] += [ i]
97
97
} )
@@ -101,12 +101,14 @@ public func run_IndexPathSubscriptRangeMutation(
101
101
102
102
@inline ( never)
103
103
public func run_IndexPathMax( _ n: Int ) {
104
- for _ in 0 ..< n {
104
+ for _ in 0 ..< n * 10 {
105
105
var val : Int ?
106
106
// Beginning max
107
107
val = decreasingIndexPath. max ( )
108
+ blackHole ( val)
108
109
// Middle max
109
110
val = increasingMaxMiddleIndexPath. max ( )
111
+ blackHole ( val)
110
112
// End max
111
113
val = increasingIndexPath. max ( )
112
114
blackHole ( val)
@@ -117,12 +119,14 @@ public func run_IndexPathMax(_ n: Int) {
117
119
118
120
@inline ( never)
119
121
public func run_IndexPathMin( _ n: Int ) {
120
- for _ in 0 ..< n {
122
+ for _ in 0 ..< n * 10 {
121
123
var val : Int ?
122
124
// Beginning min
123
125
val = increasingIndexPath. min ( )
126
+ blackHole ( val)
124
127
// Middle min
125
128
val = increasingMinMiddleIndexPath. min ( )
129
+ blackHole ( val)
126
130
// End min
127
131
val = decreasingIndexPath. min ( )
128
132
blackHole ( val)
0 commit comments