Skip to content

Commit fe5d276

Browse files
committed
Apply swift-format
1 parent 13a6385 commit fe5d276

File tree

1 file changed

+116
-86
lines changed

1 file changed

+116
-86
lines changed

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

+116-86
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,60 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import TestsUtils
1413
import Foundation
14+
import TestsUtils
1515

1616
let size = 200
1717
let tags: [BenchmarkCategory] = [.validation, .api, .IndexPath]
1818

1919
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),
4654
]
4755

4856
@inline(__always)
4957
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)
5260
}
5361

5462
@inline(__always)
5563
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)
5967
}
6068

6169
// Subscript Mutations
@@ -64,100 +72,122 @@ func indexPath(_ size: Int, middle: Int) -> IndexPath {
6472
func subscriptMutation(
6573
n: Int,
6674
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)
7681
}
82+
blackHole(ip)
83+
}
7784
}
7885

7986
@inline(never)
8087
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+
})
8493
}
8594

8695
@inline(never)
8796
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+
})
91102
}
92103

93104
// Max, Min
94105

95106
@inline(__always)
96107
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+
}
105117
}
106118

107119
// Max
108120

109121
@inline(never)
110122
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+
})
116131
}
117132

118133
@inline(never)
119134
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+
})
125143
}
126144

127145
@inline(never)
128146
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+
})
134155
}
135156

136157
// Min
137158

138159
@inline(never)
139160
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+
})
145169
}
146170

147171
@inline(never)
148172
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+
})
154181
}
155182

156183
@inline(never)
157184
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

Comments
 (0)