Skip to content

Commit 6da0389

Browse files
authored
Merge pull request #22026 from palimondo/a-tall-white-fountain-played
[benchmark] Janitor Duty: Thesaurus Heirloom
2 parents 9c755e0 + 3417ee6 commit 6da0389

28 files changed

+170
-141
lines changed

benchmark/multi-source/PrimsSplit/Prims_main.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ import TestsUtils
1515
public let PrimsSplit = BenchmarkInfo(
1616
name: "PrimsSplit",
1717
runFunction: run_PrimsSplit,
18-
tags: [.validation, .algorithm])
18+
tags: [.validation, .algorithm],
19+
legacyFactor: 5)
1920

2021
@inline(never)
2122
public func run_PrimsSplit(_ N: Int) {
22-
for _ in 1...5*N {
23+
for _ in 1...N {
2324
let nodes : [Int] = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
2425
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
2526
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,

benchmark/single-source/ErrorHandling.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import TestsUtils
1515
public let ErrorHandling = BenchmarkInfo(
1616
name: "ErrorHandling",
1717
runFunction: run_ErrorHandling,
18-
tags: [.validation, .exceptions])
18+
tags: [.validation, .exceptions],
19+
legacyFactor: 10)
1920

2021
enum PizzaError : Error {
2122
case Pepperoni, Olives, Anchovy
@@ -35,12 +36,11 @@ func doSomething() throws -> String {
3536

3637
@inline(never)
3738
public func run_ErrorHandling(_ N: Int) {
38-
for _ in 1...5000*N {
39+
for _ in 1...500*N {
3940
do {
4041
_ = try doSomething()
4142
} catch _ {
4243

4344
}
4445
}
4546
}
46-

benchmark/single-source/Hanoi.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import TestsUtils
1818
public let Hanoi = BenchmarkInfo(
1919
name: "Hanoi",
2020
runFunction: run_Hanoi,
21-
tags: [.validation, .algorithm])
21+
tags: [.validation, .algorithm],
22+
legacyFactor: 10)
2223

2324
struct Move {
2425
var from: String
@@ -46,7 +47,7 @@ class TowersOfHanoi {
4647

4748
@inline(never)
4849
public func run_Hanoi(_ N: Int) {
49-
for _ in 1...100*N {
50+
for _ in 1...10*N {
5051
let hanoi: TowersOfHanoi = TowersOfHanoi()
5152
hanoi.solve(10, start: "A", auxiliary: "B", end: "C")
5253
}

benchmark/single-source/Hash.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import TestsUtils
1818
public let HashTest = BenchmarkInfo(
1919
name: "HashTest",
2020
runFunction: run_HashTest,
21-
tags: [.validation, .algorithm])
21+
tags: [.validation, .algorithm],
22+
legacyFactor: 10)
2223

2324
class Hash {
2425
/// C'tor.
@@ -581,7 +582,7 @@ public func run_HashTest(_ N: Int) {
581582
"The quick brown fox jumps over the lazy dog." : "ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c"]
582583
let size = 50
583584

584-
for _ in 1...10*N {
585+
for _ in 1...N {
585586
// Check for precomputed values.
586587
let MD = MD5()
587588
for (K, V) in TestMD5 {

benchmark/single-source/LazyFilter.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,37 @@
1515
import TestsUtils
1616

1717
public let LazyFilter = [
18-
BenchmarkInfo(name: "LazilyFilteredArrays2", runFunction: run_LazilyFilteredArrays, tags: [.validation, .api, .Array],
19-
setUpFunction: { blackHole(filteredRange) }),
20-
BenchmarkInfo(name: "LazilyFilteredRange", runFunction: run_LazilyFilteredRange, tags: [.validation, .api, .Array]),
18+
BenchmarkInfo(name: "LazilyFilteredArrays2",
19+
runFunction: run_LazilyFilteredArrays,
20+
tags: [.validation, .api, .Array],
21+
setUpFunction: { blackHole(filteredRange) },
22+
legacyFactor: 100),
23+
BenchmarkInfo(name: "LazilyFilteredRange",
24+
runFunction: run_LazilyFilteredRange,
25+
tags: [.validation, .api, .Array],
26+
legacyFactor: 10),
2127
BenchmarkInfo(
2228
name: "LazilyFilteredArrayContains",
2329
runFunction: run_LazilyFilteredArrayContains,
2430
tags: [.validation, .api, .Array],
25-
setUpFunction: setup_LazilyFilteredArrayContains,
26-
tearDownFunction: teardown_LazilyFilteredArrayContains),
31+
setUpFunction: {
32+
multiplesOfThree = Array(1..<500).lazy.filter { $0 % 3 == 0 } },
33+
tearDownFunction: { multiplesOfThree = nil },
34+
legacyFactor: 100),
2735
]
2836

2937
@inline(never)
3038
public func run_LazilyFilteredRange(_ N: Int) {
3139
var res = 123
32-
let c = (1..<1_000_000).lazy.filter { $0 % 7 == 0 }
40+
let c = (1..<100_000).lazy.filter { $0 % 7 == 0 }
3341
for _ in 1...N {
3442
res += Array(c).count
3543
res -= Array(c).count
3644
}
3745
CheckResults(res == 123)
3846
}
3947

40-
let filteredRange = (1..<100_000).map({[$0]}).lazy.filter { $0.first! % 7 == 0 }
48+
let filteredRange = (1..<1_000).map({[$0]}).lazy.filter { $0.first! % 7 == 0 }
4149

4250
@inline(never)
4351
public func run_LazilyFilteredArrays(_ N: Int) {
@@ -52,22 +60,14 @@ public func run_LazilyFilteredArrays(_ N: Int) {
5260

5361
fileprivate var multiplesOfThree: LazyFilterCollection<Array<Int>>?
5462

55-
fileprivate func setup_LazilyFilteredArrayContains() {
56-
multiplesOfThree = Array(1..<5_000).lazy.filter { $0 % 3 == 0 }
57-
}
58-
59-
fileprivate func teardown_LazilyFilteredArrayContains() {
60-
multiplesOfThree = nil
61-
}
62-
6363
@inline(never)
6464
fileprivate func run_LazilyFilteredArrayContains(_ N: Int) {
6565
let xs = multiplesOfThree!
6666
for _ in 1...N {
6767
var filteredCount = 0
68-
for candidate in 1..<5_000 {
68+
for candidate in 1..<500 {
6969
filteredCount += xs.contains(candidate) ? 1 : 0
7070
}
71-
CheckResults(filteredCount == 1666)
71+
CheckResults(filteredCount == 166)
7272
}
7373
}

benchmark/single-source/LinkedList.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ import TestsUtils
1919
public var LinkedList = BenchmarkInfo(
2020
name: "LinkedList",
2121
runFunction: run_LinkedList,
22-
tags: [.runtime, .cpubench, .refcount]
23-
)
22+
tags: [.runtime, .cpubench, .refcount],
23+
setUpFunction: { for i in 0..<size { head = Node(n:head, d:i) } },
24+
tearDownFunction: { head = Node(n:nil, d:0) },
25+
legacyFactor: 40)
26+
27+
let size = 100
28+
var head = Node(n:nil, d:0)
2429

2530
final class Node {
2631
var next: Node?
@@ -34,16 +39,10 @@ final class Node {
3439

3540
@inline(never)
3641
public func run_LinkedList(_ N: Int) {
37-
let size = 100
38-
var head = Node(n:nil, d:0)
39-
for i in 0..<size {
40-
head = Node(n:head, d:i)
41-
}
42-
4342
var sum = 0
4443
let ref_result = size*(size-1)/2
4544
var ptr = head
46-
for _ in 1...5000*N {
45+
for _ in 1...125*N {
4746
ptr = head
4847
sum = 0
4948
while let nxt = ptr.next {

benchmark/single-source/MapReduce.swift

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,41 @@
1313
import TestsUtils
1414
import Foundation
1515

16+
let t: [BenchmarkCategory] = [.validation, .algorithm]
17+
let ts: [BenchmarkCategory] = [.validation, .algorithm, .String]
18+
1619
public let MapReduce = [
17-
BenchmarkInfo(name: "MapReduce", runFunction: run_MapReduce, tags: [.validation, .algorithm]),
18-
BenchmarkInfo(name: "MapReduceAnyCollection", runFunction: run_MapReduceAnyCollection, tags: [.validation, .algorithm]),
19-
BenchmarkInfo(name: "MapReduceAnyCollectionShort", runFunction: run_MapReduceAnyCollectionShort, tags: [.validation, .algorithm]),
20-
BenchmarkInfo(name: "MapReduceClass2", runFunction: run_MapReduceClass, tags: [.validation, .algorithm],
20+
BenchmarkInfo(name: "MapReduce", runFunction: run_MapReduce, tags: t),
21+
BenchmarkInfo(name: "MapReduceAnyCollection",
22+
runFunction: run_MapReduceAnyCollection, tags: t),
23+
BenchmarkInfo(name: "MapReduceAnyCollectionShort",
24+
runFunction: run_MapReduceAnyCollectionShort, tags: t, legacyFactor: 10),
25+
BenchmarkInfo(name: "MapReduceClass2",
26+
runFunction: run_MapReduceClass, tags: t,
2127
setUpFunction: { boxedNumbers(1000) }, tearDownFunction: releaseDecimals),
22-
BenchmarkInfo(name: "MapReduceClassShort2", runFunction: run_MapReduceClassShort, tags: [.validation, .algorithm],
28+
BenchmarkInfo(name: "MapReduceClassShort2",
29+
runFunction: run_MapReduceClassShort, tags: t,
2330
setUpFunction: { boxedNumbers(10) }, tearDownFunction: releaseDecimals),
24-
BenchmarkInfo(name: "MapReduceNSDecimalNumber", runFunction: run_MapReduceNSDecimalNumber, tags: [.validation, .algorithm],
31+
BenchmarkInfo(name: "MapReduceNSDecimalNumber",
32+
runFunction: run_MapReduceNSDecimalNumber, tags: t,
2533
setUpFunction: { decimals(1000) }, tearDownFunction: releaseDecimals),
26-
BenchmarkInfo(name: "MapReduceNSDecimalNumberShort", runFunction: run_MapReduceNSDecimalNumberShort, tags: [.validation, .algorithm],
34+
BenchmarkInfo(name: "MapReduceNSDecimalNumberShort",
35+
runFunction: run_MapReduceNSDecimalNumberShort, tags: t,
2736
setUpFunction: { decimals(10) }, tearDownFunction: releaseDecimals),
28-
BenchmarkInfo(name: "MapReduceLazyCollection", runFunction: run_MapReduceLazyCollection, tags: [.validation, .algorithm]),
29-
BenchmarkInfo(name: "MapReduceLazyCollectionShort", runFunction: run_MapReduceLazyCollectionShort, tags: [.validation, .algorithm]),
30-
BenchmarkInfo(name: "MapReduceLazySequence", runFunction: run_MapReduceLazySequence, tags: [.validation, .algorithm]),
31-
BenchmarkInfo(name: "MapReduceSequence", runFunction: run_MapReduceSequence, tags: [.validation, .algorithm]),
32-
BenchmarkInfo(name: "MapReduceShort", runFunction: run_MapReduceShort, tags: [.validation, .algorithm]),
33-
BenchmarkInfo(name: "MapReduceShortString", runFunction: run_MapReduceShortString, tags: [.validation, .algorithm, .String]),
34-
BenchmarkInfo(name: "MapReduceString", runFunction: run_MapReduceString, tags: [.validation, .algorithm, .String]),
37+
BenchmarkInfo(name: "MapReduceLazyCollection",
38+
runFunction: run_MapReduceLazyCollection, tags: t),
39+
BenchmarkInfo(name: "MapReduceLazyCollectionShort",
40+
runFunction: run_MapReduceLazyCollectionShort, tags: t),
41+
BenchmarkInfo(name: "MapReduceLazySequence",
42+
runFunction: run_MapReduceLazySequence, tags: t),
43+
BenchmarkInfo(name: "MapReduceSequence",
44+
runFunction: run_MapReduceSequence, tags: t),
45+
BenchmarkInfo(name: "MapReduceShort",
46+
runFunction: run_MapReduceShort, tags: t, legacyFactor: 10),
47+
BenchmarkInfo(name: "MapReduceShortString",
48+
runFunction: run_MapReduceShortString, tags: ts),
49+
BenchmarkInfo(name: "MapReduceString",
50+
runFunction: run_MapReduceString, tags: ts),
3551
]
3652

3753
#if _runtime(_ObjC)
@@ -83,7 +99,7 @@ public func run_MapReduceAnyCollectionShort(_ N: Int) {
8399
let numbers = AnyCollection([Int](0..<10))
84100

85101
var c = 0
86-
for _ in 1...N*10000 {
102+
for _ in 1...N*1_000 {
87103
let mapped = numbers.map { $0 &+ 5 }
88104
c += mapped.reduce(0, &+)
89105
}
@@ -95,7 +111,7 @@ public func run_MapReduceShort(_ N: Int) {
95111
var numbers = [Int](0..<10)
96112

97113
var c = 0
98-
for _ in 1...N*10000 {
114+
for _ in 1...N*1_000 {
99115
numbers = numbers.map { $0 &+ 5 }
100116
c += numbers.reduce(0, &+)
101117
}

benchmark/single-source/MonteCarloE.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ import TestsUtils
2222
public let MonteCarloE = BenchmarkInfo(
2323
name: "MonteCarloE",
2424
runFunction: run_MonteCarloE,
25-
tags: [.validation, .algorithm])
25+
tags: [.validation, .algorithm],
26+
legacyFactor: 20)
2627

2728
public func run_MonteCarloE(scale: Int) {
28-
let N = 200000*scale
29+
let N = 10_000*scale
2930
var intervals = [Bool](repeating: false, count: N)
3031
for _ in 1...N {
3132
let pos = Int(UInt(truncatingIfNeeded: Random())%UInt(N))
@@ -37,5 +38,5 @@ public func run_MonteCarloE(scale: Int) {
3738
CheckResults(numEmptyIntervals != N)
3839
let e_estimate = Double(N)/Double(numEmptyIntervals)
3940
let e = 2.71828
40-
CheckResults(abs(e_estimate - e) < 0.1)
41+
CheckResults(abs(e_estimate - e) < 0.2)
4142
}

benchmark/single-source/MonteCarloPi.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ import TestsUtils
1515
public let MonteCarloPi = BenchmarkInfo(
1616
name: "MonteCarloPi",
1717
runFunction: run_MonteCarloPi,
18-
tags: [.validation, .algorithm])
18+
tags: [.validation, .algorithm],
19+
legacyFactor: 125)
1920

2021
public func run_MonteCarloPi(scale: Int) {
2122
var pointsInside = 0
2223
let r = 10000
23-
let N = 500000*scale
24+
let N = 4_000*scale
2425
for _ in 1...N {
2526
let x = Int(truncatingIfNeeded: Random())%r
2627
let y = Int(truncatingIfNeeded: Random())%r
@@ -30,5 +31,5 @@ public func run_MonteCarloPi(scale: Int) {
3031
}
3132
let pi_estimate: Double = Double(pointsInside)*4.0/Double(N)
3233
let pi = 3.1415
33-
CheckResults(abs(pi_estimate - pi) < 0.1)
34+
CheckResults(abs(pi_estimate - pi) < 0.2)
3435
}

benchmark/single-source/NSDictionaryCastToSwift.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ import TestsUtils
2121
public let NSDictionaryCastToSwift = BenchmarkInfo(
2222
name: "NSDictionaryCastToSwift",
2323
runFunction: run_NSDictionaryCastToSwift,
24-
tags: [.validation, .api, .Dictionary, .bridging])
24+
tags: [.validation, .api, .Dictionary, .bridging],
25+
legacyFactor: 10)
2526

2627
@inline(never)
2728
public func run_NSDictionaryCastToSwift(_ N: Int) {
2829
#if _runtime(_ObjC)
2930
let NSDict = NSDictionary()
3031
var swiftDict = [String: NSObject]()
31-
for _ in 1...10000*N {
32+
for _ in 1...1_000*N {
3233
swiftDict = NSDict as! [String: NSObject]
3334
if !swiftDict.isEmpty {
3435
break

benchmark/single-source/NibbleSort.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import TestsUtils
77
public var NibbleSort = BenchmarkInfo(
88
name: "NibbleSort",
99
runFunction: run_NibbleSort,
10-
tags: [.validation]
10+
tags: [.validation],
11+
legacyFactor: 10
1112
)
1213

1314
@inline(never)
@@ -16,7 +17,7 @@ public func run_NibbleSort(_ N: Int) {
1617
let v: UInt64 = 0xbadbeef
1718
var c = NibbleCollection(v)
1819

19-
for _ in 1...10000*N {
20+
for _ in 1...1_000*N {
2021
c.val = v
2122
c.sort()
2223

benchmark/single-source/NopDeinit.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import TestsUtils
1616
public let NopDeinit = BenchmarkInfo(
1717
name: "NopDeinit",
1818
runFunction: run_NopDeinit,
19-
tags: [.regression])
19+
tags: [.regression],
20+
legacyFactor: 100)
2021

2122
class X<T : Comparable> {
2223
let deinitIters = 10000
@@ -32,7 +33,7 @@ class X<T : Comparable> {
3233
public func run_NopDeinit(_ N: Int) {
3334
for _ in 1...N {
3435
var arr :[X<Int>] = []
35-
let size = 500
36+
let size = 5
3637
for i in 1...size { arr.append(X(i)) }
3738
arr.removeAll()
3839
CheckResults(arr.count == 0)

benchmark/single-source/ObserverClosure.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import TestsUtils
1616
public let ObserverClosure = BenchmarkInfo(
1717
name: "ObserverClosure",
1818
runFunction: run_ObserverClosure,
19-
tags: [.validation])
19+
tags: [.validation],
20+
legacyFactor: 10)
2021

2122
class Observer {
2223
@inline(never)
@@ -41,7 +42,7 @@ class Signal {
4142
public func run_ObserverClosure(_ iterations: Int) {
4243
let signal = Signal()
4344
let observer = Observer()
44-
for _ in 0 ..< 10_000 * iterations {
45+
for _ in 0 ..< 1_000 * iterations {
4546
signal.subscribe { i in observer.receive(i) }
4647
}
4748
signal.send(1)

benchmark/single-source/ObserverForwarderStruct.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import TestsUtils
1515
public let ObserverForwarderStruct = BenchmarkInfo(
1616
name: "ObserverForwarderStruct",
1717
runFunction: run_ObserverForwarderStruct,
18-
tags: [.validation])
18+
tags: [.validation],
19+
legacyFactor: 5)
1920

2021
class Observer {
2122
@inline(never)
@@ -52,7 +53,7 @@ class Signal {
5253
public func run_ObserverForwarderStruct(_ iterations: Int) {
5354
let signal = Signal()
5455
let observer = Observer()
55-
for _ in 0 ..< 10_000 * iterations {
56+
for _ in 0 ..< 2_000 * iterations {
5657
signal.subscribe(Forwarder(object: observer))
5758
}
5859
signal.send(1)

0 commit comments

Comments
 (0)