Skip to content

Commit 25bd5ea

Browse files
committed
Fix styling, optimize
1 parent 477bef7 commit 25bd5ea

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

benchmark/single-source/IndexPathTest.swift

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,39 @@ let tags: [BenchmarkCategory] = [.validation, .api, .IndexPath]
2323
public let IndexPathTest = [
2424
BenchmarkInfo(
2525
name: "IndexPath.Subscript.Mutation",
26-
runFunction: { n in
27-
run_IndexPathSubscriptMutation(n * 10, size, increasingIndexPath)
28-
},
26+
runFunction: run_IndexPathSubscriptMutation,
2927
tags: tags,
3028
setUpFunction: { blackHole(increasingIndexPath) }),
3129
BenchmarkInfo(
3230
name: "IndexPath.Subscript.Range.Mutation",
33-
runFunction: { n in
34-
run_IndexPathSubscriptRangeMutation(n, size, increasingIndexPath)
35-
},
31+
runFunction: run_IndexPathSubscriptRangeMutation,
3632
tags: tags,
3733
setUpFunction: { blackHole(increasingIndexPath) }),
3834
BenchmarkInfo(
3935
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+
}),
4243
BenchmarkInfo(
4344
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+
}),
4652
]
4753

48-
@inline(__always)
4954
func indexPath(_ size: Int, reversed: Bool = false) -> IndexPath {
5055
let indexes = Array(0..<size)
5156
return IndexPath(indexes: reversed ? indexes.reversed() : indexes)
5257
}
5358

54-
@inline(__always)
5559
func indexPath(_ size: Int, middle: Int) -> IndexPath {
5660
var indexes = Array(0..<size)
5761
indexes.insert(middle, at: (indexes.count - 1) / 2)
@@ -76,22 +80,18 @@ func subscriptMutation(
7680
}
7781

7882
@inline(never)
79-
public func run_IndexPathSubscriptMutation(
80-
_ n: Int, _ count: Int, _ indexPath: IndexPath
81-
) {
83+
public func run_IndexPathSubscriptMutation(_ n: Int) {
8284
subscriptMutation(
83-
n: n, mutations: count, indexPath: indexPath,
85+
n: n * 10, mutations: size, indexPath: increasingIndexPath,
8486
mutate: { ip, i in
8587
ip[i % 4] += 1
8688
})
8789
}
8890

8991
@inline(never)
90-
public func run_IndexPathSubscriptRangeMutation(
91-
_ n: Int, _ count: Int, _ indexPath: IndexPath
92-
) {
92+
public func run_IndexPathSubscriptRangeMutation(_ n: Int) {
9393
subscriptMutation(
94-
n: n, mutations: count, indexPath: indexPath,
94+
n: n, mutations: size, indexPath: increasingIndexPath,
9595
mutate: { ip, i in
9696
ip[0..<i] += [i]
9797
})
@@ -101,12 +101,14 @@ public func run_IndexPathSubscriptRangeMutation(
101101

102102
@inline(never)
103103
public func run_IndexPathMax(_ n: Int) {
104-
for _ in 0..<n {
104+
for _ in 0..<n * 10 {
105105
var val: Int?
106106
// Beginning max
107107
val = decreasingIndexPath.max()
108+
blackHole(val)
108109
// Middle max
109110
val = increasingMaxMiddleIndexPath.max()
111+
blackHole(val)
110112
// End max
111113
val = increasingIndexPath.max()
112114
blackHole(val)
@@ -117,12 +119,14 @@ public func run_IndexPathMax(_ n: Int) {
117119

118120
@inline(never)
119121
public func run_IndexPathMin(_ n: Int) {
120-
for _ in 0..<n {
122+
for _ in 0..<n * 10 {
121123
var val: Int?
122124
// Beginning min
123125
val = increasingIndexPath.min()
126+
blackHole(val)
124127
// Middle min
125128
val = increasingMinMiddleIndexPath.min()
129+
blackHole(val)
126130
// End min
127131
val = decreasingIndexPath.min()
128132
blackHole(val)

0 commit comments

Comments
 (0)