Skip to content

Commit ebc2470

Browse files
committed
Add benchmarks
1 parent ec50cb5 commit ebc2470

File tree

4 files changed

+377
-1
lines changed

4 files changed

+377
-1
lines changed

benchmark/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ set(SWIFT_BENCH_MODULES
9292
single-source/Hash
9393
single-source/HashQuadratic
9494
single-source/Histogram
95-
single-source/InsertCharacter
95+
single-source/InsertCharacter
9696
single-source/Integrate
9797
single-source/IterateData
9898
single-source/Join
@@ -173,6 +173,7 @@ set(SWIFT_BENCH_MODULES
173173
single-source/Walsh
174174
single-source/WordCount
175175
single-source/XorLoop
176+
single-source/Zip
176177
)
177178

178179
set(SWIFT_MULTISOURCE_SWIFT_BENCHES

benchmark/single-source/Zip.swift

Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
////////////////////////////////////////////////////////////////////////////////
14+
// WARNING: This file is manually generated from .gyb template and should not
15+
// be directly modified. Instead, make changes to Zip.swift.gyb and run
16+
// scripts/generate_harness/generate_harness.py to regenerate this file.
17+
////////////////////////////////////////////////////////////////////////////////
18+
19+
import TestsUtils
20+
21+
fileprivate let collectionCount = 4096
22+
fileprivate let sumCount = collectionCount * (collectionCount - 1) / 2
23+
24+
public let Zip = [
25+
BenchmarkInfo(name: "Zip2Iteration", runFunction: run_Zip2Iteration, tags: [.validation, .api]),
26+
BenchmarkInfo(name: "ZipLongest2Iteration", runFunction: run_ZipLongest2Iteration, tags: [.validation, .api]),
27+
BenchmarkInfo(name: "Zip3Iteration", runFunction: run_Zip3Iteration, tags: [.validation, .api]),
28+
BenchmarkInfo(name: "ZipLongest3Iteration", runFunction: run_ZipLongest3Iteration, tags: [.validation, .api]),
29+
BenchmarkInfo(name: "Zip4Iteration", runFunction: run_Zip4Iteration, tags: [.validation, .api]),
30+
BenchmarkInfo(name: "ZipLongest4Iteration", runFunction: run_ZipLongest4Iteration, tags: [.validation, .api]),
31+
BenchmarkInfo(name: "Zip5Iteration", runFunction: run_Zip5Iteration, tags: [.validation, .api]),
32+
BenchmarkInfo(name: "ZipLongest5Iteration", runFunction: run_ZipLongest5Iteration, tags: [.validation, .api]),
33+
BenchmarkInfo(name: "Zip6Iteration", runFunction: run_Zip6Iteration, tags: [.validation, .api]),
34+
BenchmarkInfo(name: "ZipLongest6Iteration", runFunction: run_ZipLongest6Iteration, tags: [.validation, .api])
35+
]
36+
37+
@inline(never)
38+
public func run_Zip2Iteration (n: Int) {
39+
let collection = zip(
40+
0..<collectionCount,
41+
0..<collectionCount
42+
)
43+
44+
for _ in 1...n {
45+
var sums = (0, 0)
46+
47+
for element in collection {
48+
sums.0 += element.0
49+
sums.1 += element.1
50+
}
51+
52+
CheckResults(sums.0 == sumCount)
53+
CheckResults(sums.1 == sumCount)
54+
}
55+
}
56+
57+
@inline(never)
58+
public func run_ZipLongest2Iteration (n: Int) {
59+
let collection = zipLongest(
60+
0..<collectionCount,
61+
0..<collectionCount
62+
)
63+
64+
for _ in 1...n {
65+
var sums = (0, 0)
66+
67+
for element in collection {
68+
sums.0 += element.0!
69+
sums.1 += element.1!
70+
}
71+
72+
CheckResults(sums.0 == sumCount)
73+
CheckResults(sums.1 == sumCount)
74+
}
75+
}
76+
77+
@inline(never)
78+
public func run_Zip3Iteration (n: Int) {
79+
let collection = zip(
80+
0..<collectionCount,
81+
0..<collectionCount,
82+
0..<collectionCount
83+
)
84+
85+
for _ in 1...n {
86+
var sums = (0, 0, 0)
87+
88+
for element in collection {
89+
sums.0 += element.0
90+
sums.1 += element.1
91+
sums.2 += element.2
92+
}
93+
94+
CheckResults(sums.0 == sumCount)
95+
CheckResults(sums.1 == sumCount)
96+
CheckResults(sums.2 == sumCount)
97+
}
98+
}
99+
100+
@inline(never)
101+
public func run_ZipLongest3Iteration (n: Int) {
102+
let collection = zipLongest(
103+
0..<collectionCount,
104+
0..<collectionCount,
105+
0..<collectionCount
106+
)
107+
108+
for _ in 1...n {
109+
var sums = (0, 0, 0)
110+
111+
for element in collection {
112+
sums.0 += element.0!
113+
sums.1 += element.1!
114+
sums.2 += element.2!
115+
}
116+
117+
CheckResults(sums.0 == sumCount)
118+
CheckResults(sums.1 == sumCount)
119+
CheckResults(sums.2 == sumCount)
120+
}
121+
}
122+
123+
@inline(never)
124+
public func run_Zip4Iteration (n: Int) {
125+
let collection = zip(
126+
0..<collectionCount,
127+
0..<collectionCount,
128+
0..<collectionCount,
129+
0..<collectionCount
130+
)
131+
132+
for _ in 1...n {
133+
var sums = (0, 0, 0, 0)
134+
135+
for element in collection {
136+
sums.0 += element.0
137+
sums.1 += element.1
138+
sums.2 += element.2
139+
sums.3 += element.3
140+
}
141+
142+
CheckResults(sums.0 == sumCount)
143+
CheckResults(sums.1 == sumCount)
144+
CheckResults(sums.2 == sumCount)
145+
CheckResults(sums.3 == sumCount)
146+
}
147+
}
148+
149+
@inline(never)
150+
public func run_ZipLongest4Iteration (n: Int) {
151+
let collection = zipLongest(
152+
0..<collectionCount,
153+
0..<collectionCount,
154+
0..<collectionCount,
155+
0..<collectionCount
156+
)
157+
158+
for _ in 1...n {
159+
var sums = (0, 0, 0, 0)
160+
161+
for element in collection {
162+
sums.0 += element.0!
163+
sums.1 += element.1!
164+
sums.2 += element.2!
165+
sums.3 += element.3!
166+
}
167+
168+
CheckResults(sums.0 == sumCount)
169+
CheckResults(sums.1 == sumCount)
170+
CheckResults(sums.2 == sumCount)
171+
CheckResults(sums.3 == sumCount)
172+
}
173+
}
174+
175+
@inline(never)
176+
public func run_Zip5Iteration (n: Int) {
177+
let collection = zip(
178+
0..<collectionCount,
179+
0..<collectionCount,
180+
0..<collectionCount,
181+
0..<collectionCount,
182+
0..<collectionCount
183+
)
184+
185+
for _ in 1...n {
186+
var sums = (0, 0, 0, 0, 0)
187+
188+
for element in collection {
189+
sums.0 += element.0
190+
sums.1 += element.1
191+
sums.2 += element.2
192+
sums.3 += element.3
193+
sums.4 += element.4
194+
}
195+
196+
CheckResults(sums.0 == sumCount)
197+
CheckResults(sums.1 == sumCount)
198+
CheckResults(sums.2 == sumCount)
199+
CheckResults(sums.3 == sumCount)
200+
CheckResults(sums.4 == sumCount)
201+
}
202+
}
203+
204+
@inline(never)
205+
public func run_ZipLongest5Iteration (n: Int) {
206+
let collection = zipLongest(
207+
0..<collectionCount,
208+
0..<collectionCount,
209+
0..<collectionCount,
210+
0..<collectionCount,
211+
0..<collectionCount
212+
)
213+
214+
for _ in 1...n {
215+
var sums = (0, 0, 0, 0, 0)
216+
217+
for element in collection {
218+
sums.0 += element.0!
219+
sums.1 += element.1!
220+
sums.2 += element.2!
221+
sums.3 += element.3!
222+
sums.4 += element.4!
223+
}
224+
225+
CheckResults(sums.0 == sumCount)
226+
CheckResults(sums.1 == sumCount)
227+
CheckResults(sums.2 == sumCount)
228+
CheckResults(sums.3 == sumCount)
229+
CheckResults(sums.4 == sumCount)
230+
}
231+
}
232+
233+
@inline(never)
234+
public func run_Zip6Iteration (n: Int) {
235+
let collection = zip(
236+
0..<collectionCount,
237+
0..<collectionCount,
238+
0..<collectionCount,
239+
0..<collectionCount,
240+
0..<collectionCount,
241+
0..<collectionCount
242+
)
243+
244+
for _ in 1...n {
245+
var sums = (0, 0, 0, 0, 0, 0)
246+
247+
for element in collection {
248+
sums.0 += element.0
249+
sums.1 += element.1
250+
sums.2 += element.2
251+
sums.3 += element.3
252+
sums.4 += element.4
253+
sums.5 += element.5
254+
}
255+
256+
CheckResults(sums.0 == sumCount)
257+
CheckResults(sums.1 == sumCount)
258+
CheckResults(sums.2 == sumCount)
259+
CheckResults(sums.3 == sumCount)
260+
CheckResults(sums.4 == sumCount)
261+
CheckResults(sums.5 == sumCount)
262+
}
263+
}
264+
265+
@inline(never)
266+
public func run_ZipLongest6Iteration (n: Int) {
267+
let collection = zipLongest(
268+
0..<collectionCount,
269+
0..<collectionCount,
270+
0..<collectionCount,
271+
0..<collectionCount,
272+
0..<collectionCount,
273+
0..<collectionCount
274+
)
275+
276+
for _ in 1...n {
277+
var sums = (0, 0, 0, 0, 0, 0)
278+
279+
for element in collection {
280+
sums.0 += element.0!
281+
sums.1 += element.1!
282+
sums.2 += element.2!
283+
sums.3 += element.3!
284+
sums.4 += element.4!
285+
sums.5 += element.5!
286+
}
287+
288+
CheckResults(sums.0 == sumCount)
289+
CheckResults(sums.1 == sumCount)
290+
CheckResults(sums.2 == sumCount)
291+
CheckResults(sums.3 == sumCount)
292+
CheckResults(sums.4 == sumCount)
293+
CheckResults(sums.5 == sumCount)
294+
}
295+
}

benchmark/single-source/Zip.swift.gyb

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
% # Ignore the following warning. This _is_ the correct file to edit.
14+
////////////////////////////////////////////////////////////////////////////////
15+
// WARNING: This file is manually generated from .gyb template and should not
16+
// be directly modified. Instead, make changes to Zip.swift.gyb and run
17+
// scripts/generate_harness/generate_harness.py to regenerate this file.
18+
////////////////////////////////////////////////////////////////////////////////
19+
20+
import TestsUtils
21+
22+
fileprivate let collectionCount = 4096
23+
fileprivate let sumCount = collectionCount * (collectionCount - 1) / 2
24+
25+
%{
26+
upper_arity_bound = 6
27+
arities = range(2, upper_arity_bound + 1)
28+
}%
29+
public let Zip = [
30+
% for arity in arities:
31+
BenchmarkInfo(name: "Zip${ arity }Iteration", runFunction: run_Zip${ arity }Iteration, tags: [.validation, .api]),
32+
BenchmarkInfo(name: "ZipLongest${ arity }Iteration", runFunction: run_ZipLongest${ arity }Iteration, tags: [.validation, .api])${ "," if arity < upper_arity_bound else "" }
33+
% end
34+
]
35+
36+
% for arity in arities:
37+
@inline(never)
38+
public func run_Zip${ arity }Iteration (n: Int) {
39+
let collection = zip(
40+
${ ",\n".join([" 0..<collectionCount"] * arity) }
41+
)
42+
43+
for _ in 1...n {
44+
var sums = (${ ", ".join(["0"] * arity) })
45+
46+
for element in collection {
47+
% for element in range(0, arity):
48+
sums.${ element } += element.${ element }
49+
% end
50+
}
51+
52+
% for element in range(0, arity):
53+
CheckResults(sums.${ element } == sumCount)
54+
% end
55+
}
56+
}
57+
58+
@inline(never)
59+
public func run_ZipLongest${ arity }Iteration (n: Int) {
60+
let collection = zipLongest(
61+
${ ",\n".join([" 0..<collectionCount"] * arity) }
62+
)
63+
64+
for _ in 1...n {
65+
var sums = (${ ", ".join(["0"] * arity) })
66+
67+
for element in collection {
68+
% for element in range(0, arity):
69+
sums.${ element } += element.${ element }!
70+
% end
71+
}
72+
73+
% for element in range(0, arity):
74+
CheckResults(sums.${ element } == sumCount)
75+
% end
76+
}
77+
}${ "\n" if arity < upper_arity_bound else "" }
78+
% end

0 commit comments

Comments
 (0)