Skip to content

Commit 477bef7

Browse files
committed
Condense benchmarks
1 parent 6f103c6 commit 477bef7

File tree

1 file changed

+28
-111
lines changed

1 file changed

+28
-111
lines changed

Diff for: benchmark/single-source/IndexPathTest.swift

+28-111
Original file line numberDiff line numberDiff line change
@@ -35,50 +35,14 @@ public let IndexPathTest = [
3535
},
3636
tags: tags,
3737
setUpFunction: { blackHole(increasingIndexPath) }),
38-
39-
BenchmarkInfo(
40-
name: "IndexPath.Max.Beginning",
41-
runFunction: { n in
42-
run_IndexPathMaxBeginning(n * 25, decreasingIndexPath)
43-
},
44-
tags: tags,
45-
setUpFunction: { blackHole(decreasingIndexPath) }),
46-
BenchmarkInfo(
47-
name: "IndexPath.Max.Middle",
48-
runFunction: { n in
49-
run_IndexPathMaxMiddle(n * 25, increasingMaxMiddleIndexPath)
50-
},
51-
tags: tags,
52-
setUpFunction: { blackHole(increasingMaxMiddleIndexPath) }),
5338
BenchmarkInfo(
54-
name: "IndexPath.Max.End",
55-
runFunction: { n in
56-
run_IndexPathMaxEnd(n * 25, increasingIndexPath)
57-
},
58-
tags: tags,
59-
setUpFunction: { blackHole(increasingIndexPath) }),
60-
39+
name: "IndexPath.Max",
40+
runFunction: { n in run_IndexPathMax(n * 10) },
41+
tags: tags),
6142
BenchmarkInfo(
62-
name: "IndexPath.Min.Beginning",
63-
runFunction: { n in
64-
run_IndexPathMinBeginning(n * 25, increasingIndexPath)
65-
},
66-
tags: tags,
67-
setUpFunction: { blackHole(increasingIndexPath) }),
68-
BenchmarkInfo(
69-
name: "IndexPath.Min.Middle",
70-
runFunction: { n in
71-
run_IndexPathMinMiddle(n * 25, increasingMinMiddleIndexPath)
72-
},
73-
tags: tags,
74-
setUpFunction: { blackHole(increasingMinMiddleIndexPath) }),
75-
BenchmarkInfo(
76-
name: "IndexPath.Min.End",
77-
runFunction: { n in
78-
run_IndexPathMinEnd(n * 25, decreasingIndexPath)
79-
},
80-
tags: tags,
81-
setUpFunction: { blackHole(decreasingIndexPath) }),
43+
name: "IndexPath.Min",
44+
runFunction: { n in run_IndexPathMin(n * 10) },
45+
tags: tags),
8246
]
8347

8448
@inline(__always)
@@ -133,81 +97,34 @@ public func run_IndexPathSubscriptRangeMutation(
13397
})
13498
}
13599

136-
// Max, Min
137-
138-
@inline(__always)
139-
func maxMin(
140-
n: Int,
141-
indexPath: IndexPath,
142-
maxMinFunc: (inout IndexPath) -> Int?
143-
) {
144-
for _ in 0..<n {
145-
var ip = indexPath
146-
let found = maxMinFunc(&ip) != nil
147-
blackHole(found)
148-
}
149-
}
150-
151100
// Max
152101

153102
@inline(never)
154-
public func run_IndexPathMaxBeginning(_ n: Int, _ indexPath: IndexPath) {
155-
maxMin(
156-
n: n,
157-
indexPath: indexPath,
158-
maxMinFunc: { ip in
159-
ip.max()
160-
})
161-
}
162-
163-
@inline(never)
164-
public func run_IndexPathMaxMiddle(_ n: Int, _ indexPath: IndexPath) {
165-
maxMin(
166-
n: n,
167-
indexPath: indexPath,
168-
maxMinFunc: { ip in
169-
ip.max()
170-
})
171-
}
172-
173-
@inline(never)
174-
public func run_IndexPathMaxEnd(_ n: Int, _ indexPath: IndexPath) {
175-
maxMin(
176-
n: n,
177-
indexPath: indexPath,
178-
maxMinFunc: { ip in
179-
ip.max()
180-
})
103+
public func run_IndexPathMax(_ n: Int) {
104+
for _ in 0..<n {
105+
var val: Int?
106+
// Beginning max
107+
val = decreasingIndexPath.max()
108+
// Middle max
109+
val = increasingMaxMiddleIndexPath.max()
110+
// End max
111+
val = increasingIndexPath.max()
112+
blackHole(val)
113+
}
181114
}
182115

183116
// Min
184117

185118
@inline(never)
186-
public func run_IndexPathMinBeginning(_ n: Int, _ indexPath: IndexPath) {
187-
maxMin(
188-
n: n,
189-
indexPath: indexPath,
190-
maxMinFunc: { ip in
191-
ip.min()
192-
})
193-
}
194-
195-
@inline(never)
196-
public func run_IndexPathMinMiddle(_ n: Int, _ indexPath: IndexPath) {
197-
maxMin(
198-
n: n,
199-
indexPath: indexPath,
200-
maxMinFunc: { ip in
201-
ip.min()
202-
})
203-
}
204-
205-
@inline(never)
206-
public func run_IndexPathMinEnd(_ n: Int, _ indexPath: IndexPath) {
207-
maxMin(
208-
n: n,
209-
indexPath: indexPath,
210-
maxMinFunc: { ip in
211-
ip.min()
212-
})
119+
public func run_IndexPathMin(_ n: Int) {
120+
for _ in 0..<n {
121+
var val: Int?
122+
// Beginning min
123+
val = increasingIndexPath.min()
124+
// Middle min
125+
val = increasingMinMiddleIndexPath.min()
126+
// End min
127+
val = decreasingIndexPath.min()
128+
blackHole(val)
129+
}
213130
}

0 commit comments

Comments
 (0)