Skip to content

Commit b849427

Browse files
authored
Merge pull request #21794 from palimondo/a-tall-white-fountain-played
[WIP][benchmark] Janitor Duty: Lexicon Legacy
2 parents 8207d3d + eadb243 commit b849427

8 files changed

+74
-53
lines changed

benchmark/single-source/DeadArray.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import TestsUtils
1616
public let DeadArray = BenchmarkInfo(
1717
name: "DeadArray",
1818
runFunction: run_DeadArray,
19-
tags: [.regression, .unstable])
19+
tags: [.regression, .unstable],
20+
legacyFactor: 200
21+
)
2022

2123
@inline(__always)
2224
func debug(_ m:String) {}
@@ -28,7 +30,7 @@ func bar() { Count += 1 }
2830

2931
@inline(never)
3032
func runLoop(_ var1: Int, var2: Int) {
31-
for _ in 0..<100_000 {
33+
for _ in 0..<500 {
3234
debug("Var1: \(var1) Var2: \(var2)")
3335
bar()
3436
}
@@ -40,5 +42,5 @@ public func run_DeadArray(_ N: Int) {
4042
Count = 0
4143
runLoop(0, var2: 0)
4244
}
43-
CheckResults(Count == 100_000)
45+
CheckResults(Count == 500)
4446
}

benchmark/single-source/DictTest.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ import TestsUtils
1616
public let Dictionary = [
1717
BenchmarkInfo(name: "Dictionary", runFunction: run_Dictionary,
1818
tags: [.validation, .api, .Dictionary],
19-
setUpFunction: { blackHole(half) }),
19+
setUpFunction: { blackHole(half) },
20+
legacyFactor: 5),
2021
BenchmarkInfo(name: "DictionaryOfObjects",
2122
runFunction: run_DictionaryOfObjects,
2223
tags: [.validation, .api, .Dictionary],
23-
setUpFunction: { blackHole(halfObjects) }),
24+
setUpFunction: { blackHole(halfObjects) },
25+
legacyFactor: 5),
2426
]
2527

2628
let text = [
@@ -132,9 +134,8 @@ let half: Dictionary<String, Bool> = {
132134
}()
133135

134136
@inline(never)
135-
public func run_Dictionary(scale: Int) {
137+
public func run_Dictionary(N: Int) {
136138
var dict: Dictionary<String, Bool> = [:]
137-
let N = 5*scale
138139

139140
// Check performance of filling the dictionary:
140141
for _ in 1...N {
@@ -186,9 +187,8 @@ let halfObjects: Dictionary<Box<String>, Box<Bool>> = {
186187
}()
187188

188189
@inline(never)
189-
public func run_DictionaryOfObjects(scale: Int) {
190+
public func run_DictionaryOfObjects(N: Int) {
190191
var dict: Dictionary<Box<String>, Box<Bool>> = [:]
191-
let N = 5*scale
192192

193193
// Check performance of filling the dictionary:
194194
for _ in 1...N {

benchmark/single-source/DictTest2.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,22 @@
1313
import TestsUtils
1414

1515
public let Dictionary2 = [
16-
BenchmarkInfo(name: "Dictionary2", runFunction: run_Dictionary2, tags: [.validation, .api, .Dictionary]),
17-
BenchmarkInfo(name: "Dictionary2OfObjects", runFunction: run_Dictionary2OfObjects, tags: [.validation, .api, .Dictionary]),
16+
BenchmarkInfo(name: "Dictionary2",
17+
runFunction: run_Dictionary2,
18+
tags: [.validation, .api, .Dictionary],
19+
legacyFactor: 5),
20+
BenchmarkInfo(name: "Dictionary2OfObjects",
21+
runFunction: run_Dictionary2OfObjects,
22+
tags: [.validation, .api, .Dictionary],
23+
legacyFactor: 5),
1824
]
1925

2026
@inline(never)
2127
public func run_Dictionary2(_ N: Int) {
2228
let size = 500
2329
let ref_result = 199
2430
var res = 0
25-
for _ in 1...5*N {
31+
for _ in 1...N {
2632
var x: [String: Int] = [:]
2733
for i in 1...size {
2834
x[String(i, radix:16)] = i
@@ -64,7 +70,7 @@ public func run_Dictionary2OfObjects(_ N: Int) {
6470
let size = 500
6571
let ref_result = 199
6672
var res = 0
67-
for _ in 1...5*N {
73+
for _ in 1...N {
6874
var x: [Box<String>:Box<Int>] = [:]
6975
for i in 1...size {
7076
x[Box(String(i, radix:16))] = Box(i)

benchmark/single-source/DictionaryCompactMapValues.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
import TestsUtils
33

44
public let DictionaryCompactMapValues = [
5-
BenchmarkInfo(name: "DictionaryCompactMapValuesOfNilValue", runFunction: run_DictionaryCompactMapValuesOfNilValue, tags: [.validation, .api, .Dictionary]),
6-
BenchmarkInfo(name: "DictionaryCompactMapValuesOfCastValue", runFunction: run_DictionaryCompactMapValuesOfCastValue, tags: [.validation, .api, .Dictionary]),
5+
BenchmarkInfo(name: "DictionaryCompactMapValuesOfNilValue",
6+
runFunction: run_DictionaryCompactMapValuesOfNilValue,
7+
tags: [.validation, .api, .Dictionary],
8+
legacyFactor: 50),
9+
BenchmarkInfo(name: "DictionaryCompactMapValuesOfCastValue",
10+
runFunction: run_DictionaryCompactMapValuesOfCastValue,
11+
tags: [.validation, .api, .Dictionary],
12+
legacyFactor: 50),
713
]
814

915
@inline(never)
@@ -27,7 +33,7 @@ public func run_DictionaryCompactMapValuesOfNilValue(_ N: Int) {
2733
}
2834

2935
var newDict = [Int: Int]()
30-
for _ in 1...1000*N {
36+
for _ in 1...20*N {
3137
newDict = dict.compactMapValues({$0})
3238
if newDict != refDict {
3339
break
@@ -41,7 +47,7 @@ public func run_DictionaryCompactMapValuesOfNilValue(_ N: Int) {
4147
public func run_DictionaryCompactMapValuesOfCastValue(_ N: Int) {
4248
let size = 100
4349
var dict = [Int: String](minimumCapacity: size)
44-
50+
4551
// Fill Dictionary
4652
for i in 1...size {
4753
if i % 2 == 0 {
@@ -50,7 +56,7 @@ public func run_DictionaryCompactMapValuesOfCastValue(_ N: Int) {
5056
dict[i] = "\(i)"
5157
}
5258
}
53-
59+
5460
CheckResults(dict.count == size)
5561

5662
var refDict = [Int: Int]()
@@ -59,13 +65,12 @@ public func run_DictionaryCompactMapValuesOfCastValue(_ N: Int) {
5965
}
6066

6167
var newDict = [Int: Int]()
62-
for _ in 1...1000*N {
68+
for _ in 1...20*N {
6369
newDict = dict.compactMapValues(Int.init)
6470
if newDict != refDict {
6571
break
6672
}
6773
}
68-
74+
6975
CheckResults(newDict == refDict)
7076
}
71-

benchmark/single-source/DictionaryLiteral.swift

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

2223
@inline(never)
2324
func makeDictionary() -> [Int: Int] {
@@ -26,7 +27,7 @@ func makeDictionary() -> [Int: Int] {
2627

2728
@inline(never)
2829
public func run_DictionaryLiteral(_ N: Int) {
29-
for _ in 1...10000*N {
30+
for _ in 1...1000*N {
3031
_ = makeDictionary()
3132
}
3233
}

benchmark/single-source/DictionaryRemove.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
// rdar://problem/19804127
1515
import TestsUtils
1616

17+
let t: [BenchmarkCategory] = [.validation, .api, .Dictionary]
18+
1719
public let DictionaryRemove = [
18-
BenchmarkInfo(name: "DictionaryRemove", runFunction: run_DictionaryRemove, tags: [.validation, .api, .Dictionary]),
19-
BenchmarkInfo(name: "DictionaryRemoveOfObjects", runFunction: run_DictionaryRemoveOfObjects, tags: [.validation, .api, .Dictionary]),
20+
BenchmarkInfo(name: "DictionaryRemove",
21+
runFunction: run_DictionaryRemove, tags: t, legacyFactor: 10),
22+
BenchmarkInfo(name: "DictionaryRemoveOfObjects",
23+
runFunction: run_DictionaryRemoveOfObjects, tags: t, legacyFactor: 100),
2024
]
2125

2226
@inline(never)
@@ -31,7 +35,7 @@ public func run_DictionaryRemove(_ N: Int) {
3135
CheckResults(dict.count == size)
3236

3337
var tmpDict = dict
34-
for _ in 1...1000*N {
38+
for _ in 1...100*N {
3539
tmpDict = dict
3640
// Empty dictionary
3741
for i in 1...size {
@@ -73,7 +77,7 @@ public func run_DictionaryRemoveOfObjects(_ N: Int) {
7377
CheckResults(dict.count == size)
7478

7579
var tmpDict = dict
76-
for _ in 1...1000*N {
80+
for _ in 1...10*N {
7781
tmpDict = dict
7882
// Empty dictionary
7983
for i in 1...size {

benchmark/single-source/DictionarySubscriptDefault.swift

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,25 @@ public let DictionarySubscriptDefault = [
2121
tags: [.validation, .api, .Dictionary]),
2222
BenchmarkInfo(name: "DictionarySubscriptDefaultMutationOfObjects",
2323
runFunction: run_DictionarySubscriptDefaultMutationOfObjects,
24-
tags: [.validation, .api, .Dictionary]),
24+
tags: [.validation, .api, .Dictionary], legacyFactor: 20),
2525
BenchmarkInfo(name: "DictionarySubscriptDefaultMutationArrayOfObjects",
2626
runFunction:
2727
run_DictionarySubscriptDefaultMutationArrayOfObjects,
28-
tags: [.validation, .api, .Dictionary]),
28+
tags: [.validation, .api, .Dictionary], legacyFactor: 20),
2929
]
3030

31-
let count = 10_000
32-
let result = count / 100
33-
3431
@inline(never)
3532
public func run_DictionarySubscriptDefaultMutation(_ N: Int) {
3633
for _ in 1...N {
3734

3835
var dict = [Int: Int]()
3936

40-
for i in 0..<count {
37+
for i in 0..<10_000 {
4138
dict[i % 100, default: 0] += 1
4239
}
4340

4441
CheckResults(dict.count == 100)
45-
CheckResults(dict[0]! == result)
42+
CheckResults(dict[0]! == 100)
4643
}
4744
}
4845

@@ -52,12 +49,12 @@ public func run_DictionarySubscriptDefaultMutationArray(_ N: Int) {
5249

5350
var dict = [Int: [Int]]()
5451

55-
for i in 0..<count {
52+
for i in 0..<10_000 {
5653
dict[i % 100, default: []].append(i)
5754
}
5855

5956
CheckResults(dict.count == 100)
60-
CheckResults(dict[0]!.count == result)
57+
CheckResults(dict[0]!.count == 100)
6158
}
6259
}
6360

@@ -99,26 +96,26 @@ public func run_DictionarySubscriptDefaultMutationOfObjects(_ N: Int) {
9996

10097
var dict = [Box<Int>: Box<Int>]()
10198

102-
for i in 0..<count {
103-
dict[Box(i % 100), default: Box(0)].mutateValue { $0 += 1 }
99+
for i in 0..<500 {
100+
dict[Box(i % 5), default: Box(0)].mutateValue { $0 += 1 }
104101
}
105102

106-
CheckResults(dict.count == 100)
107-
CheckResults(dict[Box(0)]!.value == result)
103+
CheckResults(dict.count == 5)
104+
CheckResults(dict[Box(0)]!.value == 100)
108105
}
109106
}
110107

111108
@inline(never)
112109
public func run_DictionarySubscriptDefaultMutationArrayOfObjects(_ N: Int) {
113-
for _ in 1...N {
110+
for _ in 1...N {
114111

115112
var dict = [Box<Int>: [Box<Int>]]()
116113

117-
for i in 0..<count {
118-
dict[Box(i % 100), default: []].append(Box(i))
114+
for i in 0..<500 {
115+
dict[Box(i % 5), default: []].append(Box(i))
119116
}
120117

121-
CheckResults(dict.count == 100)
122-
CheckResults(dict[Box(0)]!.count == result)
118+
CheckResults(dict.count == 5)
119+
CheckResults(dict[Box(0)]!.count == 100)
123120
}
124121
}

benchmark/single-source/DictionarySwap.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@
1414
// rdar://problem/19804127
1515
import TestsUtils
1616

17+
let t: [BenchmarkCategory] = [.validation, .api, .Dictionary]
18+
1719
public let DictionarySwap = [
18-
BenchmarkInfo(name: "DictionarySwap", runFunction: run_DictionarySwap, tags: [.validation, .api, .Dictionary]),
19-
BenchmarkInfo(name: "DictionarySwapOfObjects", runFunction: run_DictionarySwapOfObjects, tags: [.validation, .api, .Dictionary]),
20-
BenchmarkInfo(name: "DictionarySwapAt", runFunction: run_DictionarySwapAt, tags: [.validation, .api, .Dictionary]),
21-
BenchmarkInfo(name: "DictionarySwapAtOfObjects", runFunction: run_DictionarySwapAtOfObjects, tags: [.validation, .api, .Dictionary]),
20+
BenchmarkInfo(name: "DictionarySwap",
21+
runFunction: run_DictionarySwap, tags: t, legacyFactor: 4),
22+
BenchmarkInfo(name: "DictionarySwapOfObjects",
23+
runFunction: run_DictionarySwapOfObjects, tags: t, legacyFactor: 40),
24+
BenchmarkInfo(name: "DictionarySwapAt",
25+
runFunction: run_DictionarySwapAt, tags: t, legacyFactor: 4),
26+
BenchmarkInfo(name: "DictionarySwapAtOfObjects",
27+
runFunction: run_DictionarySwapAtOfObjects, tags: t, legacyFactor: 40),
2228
]
2329

2430
@inline(never)
@@ -33,7 +39,7 @@ public func run_DictionarySwap(_ N: Int) {
3339
CheckResults(dict.count == size)
3440

3541
var swapped = false
36-
for _ in 1...10000*N {
42+
for _ in 1...2500*N {
3743
(dict[25], dict[75]) = (dict[75]!, dict[25]!)
3844
swapped = !swapped
3945
if !swappedCorrectly(swapped, dict[25]!, dict[75]!) {
@@ -56,7 +62,7 @@ public func run_DictionarySwapAt(_ N: Int) {
5662
CheckResults(dict.count == size)
5763

5864
var swapped = false
59-
for _ in 1...10000*N {
65+
for _ in 1...2500*N {
6066
let i25 = dict.index(forKey: 25)!
6167
let i75 = dict.index(forKey: 75)!
6268

@@ -104,7 +110,7 @@ public func run_DictionarySwapOfObjects(_ N: Int) {
104110
CheckResults(dict.count == size)
105111

106112
var swapped = false
107-
for _ in 1...10000*N {
113+
for _ in 1...250*N {
108114
let b1 = Box(25)
109115
let b2 = Box(75)
110116
(dict[b1], dict[b2]) = (dict[b2]!, dict[b1]!)
@@ -129,7 +135,7 @@ public func run_DictionarySwapAtOfObjects(_ N: Int) {
129135
CheckResults(dict.count == size)
130136

131137
var swapped = false
132-
for _ in 1...10000*N {
138+
for _ in 1...250*N {
133139
let b25 = Box(25)
134140
let b75 = Box(75)
135141
let i25 = dict.index(forKey: b25)!

0 commit comments

Comments
 (0)