Skip to content

Commit b6a069c

Browse files
committed
[benchmark] SequenceAlgos Legacy Factor
Also inlined runFunctions and setUpFunctions.
1 parent f104383 commit b6a069c

File tree

1 file changed

+33
-66
lines changed

1 file changed

+33
-66
lines changed
Lines changed: 33 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- ArrayAppend.swift ------------------------------------------------===//
1+
//===--- SequenceAlgos.swift ----------------------------------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -18,13 +18,34 @@ import TestsUtils
1818
// To avoid too many little micro benchmarks, it measures them all together
1919
// for each sequence type.
2020

21+
let t: [BenchmarkCategory] = [.validation, .api]
22+
2123
public let SequenceAlgos = [
22-
BenchmarkInfo(name: "SequenceAlgosList", runFunction: run_SequenceAlgosList, tags: [.validation, .api], setUpFunction: { buildWorkload() }, tearDownFunction: nil),
23-
BenchmarkInfo(name: "SequenceAlgosArray", runFunction: run_SequenceAlgosArray, tags: [.validation, .api], setUpFunction: { buildWorkload() }, tearDownFunction: nil),
24-
BenchmarkInfo(name: "SequenceAlgosContiguousArray", runFunction: run_SequenceAlgosContiguousArray, tags: [.validation, .api], setUpFunction: { buildWorkload() }, tearDownFunction: nil),
25-
BenchmarkInfo(name: "SequenceAlgosRange", runFunction: run_SequenceAlgosRange, tags: [.validation, .api], setUpFunction: { buildWorkload() }, tearDownFunction: nil),
26-
BenchmarkInfo(name: "SequenceAlgosUnfoldSequence", runFunction: run_SequenceAlgosUnfoldSequence, tags: [.validation, .api], setUpFunction: { buildWorkload() }, tearDownFunction: nil),
27-
BenchmarkInfo(name: "SequenceAlgosAnySequence", runFunction: run_SequenceAlgosAnySequence, tags: [.validation, .api], setUpFunction: { buildWorkload() }, tearDownFunction: nil),
24+
BenchmarkInfo(name: "SequenceAlgosList", runFunction: { for _ in 0..<$0 {
25+
benchmarkSequenceAlgos(s: l, n: n)
26+
benchmarkEquatableSequenceAlgos(s: l, n: n)
27+
}}, tags: t, setUpFunction: { blackHole(l) }, legacyFactor: 10),
28+
BenchmarkInfo(name: "SequenceAlgosArray", runFunction: { for _ in 0..<$0 {
29+
benchmarkSequenceAlgos(s: a, n: a.count)
30+
benchmarkEquatableSequenceAlgos(s: a, n: a.count)
31+
}}, tags: t, setUpFunction: { blackHole(a) }, legacyFactor: 10),
32+
BenchmarkInfo(name: "SequenceAlgosContiguousArray",
33+
runFunction: { for _ in 0..<$0 {
34+
benchmarkSequenceAlgos(s: c, n: c.count)
35+
benchmarkEquatableSequenceAlgos(s: c, n: c.count)
36+
}}, tags: t, setUpFunction: { blackHole(c) }, legacyFactor: 10),
37+
BenchmarkInfo(name: "SequenceAlgosRange", runFunction: { for _ in 0..<$0 {
38+
benchmarkSequenceAlgos(s: r, n: r.count)
39+
benchmarkEquatableSequenceAlgos(s: r, n: r.count)
40+
}}, tags: t, legacyFactor: 10),
41+
BenchmarkInfo(name: "SequenceAlgosUnfoldSequence",
42+
runFunction: { for _ in 0..<$0 {
43+
benchmarkSequenceAlgos(s: s, n: n)
44+
}}, tags: t, setUpFunction: { blackHole(s) }, legacyFactor: 10),
45+
BenchmarkInfo(name: "SequenceAlgosAnySequence",
46+
runFunction: { for _ in 0..<$0 {
47+
benchmarkSequenceAlgos(s: y, n: n/10)
48+
}}, tags: t, setUpFunction: { blackHole(y) }, legacyFactor: 100),
2849
]
2950

3051
extension List: Sequence {
@@ -55,79 +76,25 @@ func benchmarkSequenceAlgos<S: Sequence>(s: S, n: Int) where S.Element == Int {
5576
CheckResults(s.starts(with: s))
5677
}
5778

58-
let n = 10_000
79+
let n = 1_000
5980
let r = 0..<(n*100)
6081
let l = List(0..<n)
6182
let c = ContiguousArray(0..<(n*100))
6283
let a = Array(0..<(n*100))
63-
let y = AnySequence(0..<n)
84+
let y = AnySequence(0..<n/10)
6485
let s = sequence(first: 0, next: { $0 < n&-1 ? $0&+1 : nil})
6586

66-
func buildWorkload() {
67-
blackHole(l.makeIterator())
68-
blackHole(c.makeIterator())
69-
blackHole(a.makeIterator())
70-
blackHole(y.makeIterator())
71-
blackHole(s.makeIterator())
72-
}
73-
74-
func benchmarkEquatableSequenceAlgos<S: Sequence>(s: S, n: Int) where S.Element == Int, S: Equatable {
87+
func benchmarkEquatableSequenceAlgos<S: Sequence>(s: S, n: Int)
88+
where S.Element == Int, S: Equatable {
7589
CheckResults(repeatElement(s, count: 1).contains(s))
7690
CheckResults(!repeatElement(s, count: 1).contains { $0 != s })
7791
}
7892

79-
@inline(never)
80-
public func run_SequenceAlgosRange(_ N: Int) {
81-
for _ in 0..<N {
82-
benchmarkSequenceAlgos(s: r, n: r.count)
83-
benchmarkEquatableSequenceAlgos(s: r, n: r.count)
84-
}
85-
}
86-
87-
@inline(never)
88-
public func run_SequenceAlgosArray(_ N: Int) {
89-
for _ in 0..<N {
90-
benchmarkSequenceAlgos(s: a, n: a.count)
91-
benchmarkEquatableSequenceAlgos(s: a, n: a.count)
92-
}
93-
}
94-
95-
@inline(never)
96-
public func run_SequenceAlgosContiguousArray(_ N: Int) {
97-
for _ in 0..<N {
98-
benchmarkSequenceAlgos(s: c, n: c.count)
99-
benchmarkEquatableSequenceAlgos(s: c, n: c.count)
100-
}
101-
}
102-
103-
@inline(never)
104-
public func run_SequenceAlgosAnySequence(_ N: Int) {
105-
for _ in 0..<N {
106-
benchmarkSequenceAlgos(s: y, n: n)
107-
}
108-
}
109-
110-
@inline(never)
111-
public func run_SequenceAlgosUnfoldSequence(_ N: Int) {
112-
for _ in 0..<N {
113-
benchmarkSequenceAlgos(s: s, n: n)
114-
}
115-
}
116-
117-
@inline(never)
118-
public func run_SequenceAlgosList(_ N: Int) {
119-
for _ in 0..<N {
120-
benchmarkSequenceAlgos(s: l, n: n)
121-
benchmarkEquatableSequenceAlgos(s: l, n: n)
122-
}
123-
}
124-
12593
enum List<Element> {
12694
case end
12795
indirect case node(Element, List<Element>)
128-
96+
12997
init<S: BidirectionalCollection>(_ elements: S) where S.Element == Element {
13098
self = elements.reversed().reduce(.end) { .node($1,$0) }
13199
}
132100
}
133-

0 commit comments

Comments
 (0)