Skip to content

Commit 80b9517

Browse files
authored
Merge pull request #22296 from palimondo/a-tall-white-fountain-played
[benchmark] Janitor Duty: Sisyphus Legacy
2 parents 98e3f04 + ff4e8de commit 80b9517

File tree

8 files changed

+86
-111
lines changed

8 files changed

+86
-111
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-

benchmark/single-source/SetTests.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,29 +296,29 @@ public let SetTests = [
296296
// Legacy benchmarks, kept for continuity with previous releases.
297297
BenchmarkInfo(
298298
name: "SetExclusiveOr", // ~"SetSymmetricDifferenceInt0"
299-
runFunction: { n in run_SetSymmetricDifferenceInt(setAB, setCD, countABCD, 100 * n) },
299+
runFunction: { n in run_SetSymmetricDifferenceInt(setAB, setCD, countABCD, 10 * n) },
300300
tags: [.validation, .api, .Set],
301-
setUpFunction: { blackHole([setAB, setCD]) }),
301+
setUpFunction: { blackHole([setAB, setCD]) }, legacyFactor: 10),
302302
BenchmarkInfo(
303303
name: "SetExclusiveOr_OfObjects", // ~"SetSymmetricDifferenceBox0"
304-
runFunction: { n in run_SetSymmetricDifferenceBox(setOAB, setOCD, countABCD, 100 * n) },
304+
runFunction: { n in run_SetSymmetricDifferenceBox(setOAB, setOCD, countABCD, 10 * n) },
305305
tags: [.validation, .api, .Set],
306-
setUpFunction: { blackHole([setOAB, setOCD]) }),
306+
setUpFunction: { blackHole([setOAB, setOCD]) }, legacyFactor: 10),
307307
BenchmarkInfo(
308308
name: "SetIntersect", // ~"SetIntersectionInt0"
309-
runFunction: { n in run_SetIntersectionInt(setAB, setCD, 0, 100 * n) },
309+
runFunction: { n in run_SetIntersectionInt(setAB, setCD, 0, 10 * n) },
310310
tags: [.validation, .api, .Set],
311-
setUpFunction: { blackHole([setAB, setCD]) }),
311+
setUpFunction: { blackHole([setAB, setCD]) }, legacyFactor: 10),
312312
BenchmarkInfo(
313313
name: "SetUnion", // ~"SetUnionInt0"
314-
runFunction: { n in run_SetUnionInt(setAB, setCD, countABCD, 100 * n) },
314+
runFunction: { n in run_SetUnionInt(setAB, setCD, countABCD, 10 * n) },
315315
tags: [.validation, .api, .Set],
316-
setUpFunction: { blackHole([setAB, setCD]) }),
316+
setUpFunction: { blackHole([setAB, setCD]) }, legacyFactor: 10),
317317
BenchmarkInfo(
318318
name: "SetUnion_OfObjects", // ~"SetUnionBox0"
319-
runFunction: { n in run_SetUnionBox(setOAB, setOCD, countABCD, 100 * n) },
319+
runFunction: { n in run_SetUnionBox(setOAB, setOCD, countABCD, 10 * n) },
320320
tags: [.validation, .api, .Set],
321-
setUpFunction: { blackHole([setOAB, setOCD]) }),
321+
setUpFunction: { blackHole([setOAB, setOCD]) }, legacyFactor: 10),
322322
]
323323

324324
@inline(never)

benchmark/single-source/SortIntPyramids.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ public let SortIntPyramids = [
88
BenchmarkInfo(
99
name: "SortIntPyramid",
1010
runFunction: run_SortIntPyramid,
11-
tags: [.validation, .api, .algorithm]),
11+
tags: [.validation, .api, .algorithm],
12+
legacyFactor: 5),
1213
BenchmarkInfo(
1314
name: "SortAdjacentIntPyramids",
1415
runFunction: run_SortAdjacentIntPyramids,
15-
tags: [.validation, .api, .algorithm]),
16+
tags: [.validation, .api, .algorithm],
17+
legacyFactor: 5),
1618
]
1719

1820
// let A - array sorted in ascending order,
@@ -51,7 +53,7 @@ let adjacentPyramidsTemplate: [Int] = (1...aPH) + (1...aPH).reversed()
5153

5254
@inline(never)
5355
public func run_SortIntPyramid(_ N: Int) {
54-
for _ in 1...25*N {
56+
for _ in 1...5*N {
5557
var pyramid = pyramidTemplate
5658

5759
// sort pyramid in place.
@@ -64,7 +66,7 @@ public func run_SortIntPyramid(_ N: Int) {
6466

6567
@inline(never)
6668
public func run_SortAdjacentIntPyramids(_ N: Int) {
67-
for _ in 1...25*N {
69+
for _ in 1...5*N {
6870
var adjacentPyramids = adjacentPyramidsTemplate
6971
adjacentPyramids.sort()
7072
// Check whether pyramid is sorted.

benchmark/single-source/SortLargeExistentials.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import TestsUtils
1717
public let SortLargeExistentials = BenchmarkInfo(
1818
name: "SortLargeExistentials",
1919
runFunction: run_SortLargeExistentials,
20-
tags: [.validation, .api, .algorithm])
20+
tags: [.validation, .api, .algorithm],
21+
legacyFactor: 100)
2122

2223
protocol LetterKind {
2324
var value: String { get }
@@ -74,7 +75,7 @@ let lettersTemplate : [LetterKind] = [
7475

7576
@inline(never)
7677
public func run_SortLargeExistentials(_ N: Int) {
77-
for _ in 1...100*N {
78+
for _ in 1...N {
7879
var letters = lettersTemplate
7980

8081
letters.sort {

benchmark/single-source/SortStrings.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
//===----------------------------------------------------------------------===//
1212
import TestsUtils
1313

14+
let t: [BenchmarkCategory] = [.validation, .api, .algorithm, .String]
1415
// Sort an array of strings using an explicit sort predicate.
1516
public let SortStrings = [
16-
BenchmarkInfo(name: "SortSortedStrings", runFunction: run_SortSortedStrings, tags: [.validation, .api, .algorithm, .String],
17+
BenchmarkInfo(name: "SortSortedStrings",
18+
runFunction: run_SortSortedStrings, tags: t,
1719
setUpFunction: { blackHole(sortedWords) }),
18-
BenchmarkInfo(name: "SortStrings", runFunction: run_SortStrings, tags: [.validation, .api, .algorithm, .String],
20+
BenchmarkInfo(name: "SortStrings",
21+
runFunction: run_SortStrings, tags: t,
1922
setUpFunction: { blackHole(words) }),
20-
BenchmarkInfo(name: "SortStringsUnicode", runFunction: run_SortStringsUnicode, tags: [.validation, .api, .algorithm, .String],
21-
setUpFunction: { blackHole(unicodeWords) }),
23+
BenchmarkInfo(name: "SortStringsUnicode",
24+
runFunction: run_SortStringsUnicode, tags: t,
25+
setUpFunction: { blackHole(unicodeWords) }, legacyFactor: 5),
2226
]
2327

2428
let sortedWords = words.sorted()
@@ -2050,7 +2054,7 @@ var unicodeWords: [String] = [
20502054
]
20512055

20522056
public func run_SortStringsUnicode(_ N: Int) {
2053-
for _ in 1...5*N {
2057+
for _ in 1...N {
20542058
benchSortStrings(unicodeWords)
20552059
}
20562060
}

benchmark/single-source/StackPromo.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import TestsUtils
1414
public let StackPromo = BenchmarkInfo(
1515
name: "StackPromo",
1616
runFunction: run_StackPromo,
17-
tags: [.regression])
17+
tags: [.regression],
18+
legacyFactor: 100)
1819

1920
protocol Proto {
2021
func at() -> Int
@@ -43,19 +44,12 @@ class Foo : Proto {
4344
@inline(never)
4445
func work(_ f: Foo) -> Int {
4546
var r = 0
46-
for _ in 0..<100_000 {
47+
for _ in 0..<1_000 {
4748
r += testStackAllocation(f)
4849
}
4950
return r
5051
}
5152

52-
@inline(never)
53-
func hole(_ use: Int, _ N: Int) {
54-
if (N == 0) {
55-
print("use: \(use)")
56-
}
57-
}
58-
5953
public func run_StackPromo(_ N: Int) {
6054
let foo = Foo()
6155
var r = 0
@@ -66,5 +60,5 @@ public func run_StackPromo(_ N: Int) {
6660
r -= work(foo)
6761
}
6862
}
69-
hole(r, N)
63+
blackHole(r)
7064
}

benchmark/single-source/TwoSum.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import TestsUtils
1717
public let TwoSum = BenchmarkInfo(
1818
name: "TwoSum",
1919
runFunction: run_TwoSum,
20-
tags: [.validation, .api, .Dictionary, .Array, .algorithm])
20+
tags: [.validation, .api, .Dictionary, .Array, .algorithm],
21+
legacyFactor: 2)
2122

2223
let array = [
2324
959, 81, 670, 727, 416, 171, 401, 398, 707, 596, 200, 9, 414, 98, 43,
@@ -61,7 +62,7 @@ public func run_TwoSum(_ N: Int) {
6162
var i1: Int?
6263
var i2: Int?
6364
var Dict: Dictionary<Int, Int> = [:]
64-
for _ in 1...2*N {
65+
for _ in 1...N {
6566
for Sum in 500..<600 {
6667
Dict = [:]
6768
i1 = nil

0 commit comments

Comments
 (0)