Skip to content

Commit b2776f3

Browse files
committed
[benchmark] [Equal,Less]Substring setup overhead
1 parent b7f6813 commit b2776f3

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

benchmark/single-source/Substring.swift

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public let SubstringTest = [
3131

3232
// A string that doesn't fit in small string storage and doesn't fit in Latin-1
3333
let longWide = "fὢasὢodὢijὢadὢolὢsjὢalὢsdὢjlὢasὢdfὢijὢliὢsdὢjøὢslὢdiὢalὢiὢ"
34+
let (s1, ss1) = equivalentWithDistinctBuffers()
35+
let (s2, ss2) = equivalentWithDistinctBuffers()
3436

3537
@inline(never)
3638
public func run_SubstringFromLongString(_ N: Int) {
@@ -89,33 +91,33 @@ private func equivalentWithDistinctBuffers() -> (String, Substring) {
8991

9092
@inline(never)
9193
public func run_EqualStringSubstring(_ N: Int) {
92-
let (a, b) = equivalentWithDistinctBuffers()
94+
let (a, b) = (s1, ss1)
9395
for _ in 1...N*500 {
9496
blackHole(a == b)
9597
}
9698
}
9799

98100
@inline(never)
99101
public func run_EqualSubstringString(_ N: Int) {
100-
let (a, b) = equivalentWithDistinctBuffers()
102+
let (a, b) = (s1, ss1)
101103
for _ in 1...N*500 {
102104
blackHole(b == a)
103105
}
104106
}
105107

106108
@inline(never)
107109
public func run_EqualSubstringSubstring(_ N: Int) {
108-
let (_, a) = equivalentWithDistinctBuffers()
109-
let (_, b) = equivalentWithDistinctBuffers()
110+
let (_, a) = (s1, ss1)
111+
let (_, b) = (s2, ss2)
110112
for _ in 1...N*500 {
111113
blackHole(a == b)
112114
}
113115
}
114116

115117
@inline(never)
116118
public func run_EqualSubstringSubstringGenericEquatable(_ N: Int) {
117-
let (_, a) = equivalentWithDistinctBuffers()
118-
let (_, b) = equivalentWithDistinctBuffers()
119+
let (_, a) = (s1, ss1)
120+
let (_, b) = (s2, ss2)
119121
func check<T>(_ x: T, _ y: T) where T : Equatable {
120122
blackHole(x == y)
121123
}
@@ -132,24 +134,24 @@ where T : StringProtocol, U : StringProtocol {
132134

133135
@inline(never)
134136
public func run _EqualStringSubstringGenericStringProtocol(_ N: Int) {
135-
let (a, b) = equivalentWithDistinctBuffers()
137+
let (a, b) = (s1, ss1)
136138
for _ in 1...N*500 {
137139
checkEqual(a, b)
138140
}
139141
}
140142

141143
@inline(never)
142144
public func run _EqualSubstringStringGenericStringProtocol(_ N: Int) {
143-
let (a, b) = equivalentWithDistinctBuffers()
145+
let (a, b) = (s1, ss1)
144146
for _ in 1...N*500 {
145147
checkEqual(b, a)
146148
}
147149
}
148150

149151
@inline(never)
150152
public func run _EqualSubstringSubstringGenericStringProtocol(_ N: Int) {
151-
let (_, a) = equivalentWithDistinctBuffers()
152-
let (_, b) = equivalentWithDistinctBuffers()
153+
let (_, a) = (s1, ss1)
154+
let (_, b) = (s2, ss2)
153155
for _ in 1...N*500 {
154156
checkEqual(a, b)
155157
}
@@ -161,15 +163,15 @@ public func run _EqualSubstringSubstringGenericStringProtocol(_ N: Int) {
161163
/*
162164
@inline(never)
163165
public func run _LessStringSubstring(_ N: Int) {
164-
let (a, b) = equivalentWithDistinctBuffers()
166+
let (a, b) = (s1, ss1)
165167
for _ in 1...N*500 {
166168
blackHole(a < b)
167169
}
168170
}
169171

170172
@inline(never)
171173
public func run _LessSubstringString(_ N: Int) {
172-
let (a, b) = equivalentWithDistinctBuffers()
174+
let (a, b) = (s1, ss1)
173175
for _ in 1...N*500 {
174176
blackHole(b < a)
175177
}
@@ -178,17 +180,17 @@ public func run _LessSubstringString(_ N: Int) {
178180

179181
@inline(never)
180182
public func run_LessSubstringSubstring(_ N: Int) {
181-
let (_, a) = equivalentWithDistinctBuffers()
182-
let (_, b) = equivalentWithDistinctBuffers()
183+
let (_, a) = (s1, ss1)
184+
let (_, b) = (s2, ss2)
183185
for _ in 1...N*500 {
184186
blackHole(a < b)
185187
}
186188
}
187189

188190
@inline(never)
189191
public func run_LessSubstringSubstringGenericComparable(_ N: Int) {
190-
let (_, a) = equivalentWithDistinctBuffers()
191-
let (_, b) = equivalentWithDistinctBuffers()
192+
let (_, a) = (s1, ss1)
193+
let (_, b) = (s2, ss2)
192194
func check<T>(_ x: T, _ y: T) where T : Comparable {
193195
blackHole(x < y)
194196
}
@@ -251,24 +253,24 @@ where T : StringProtocol, U : StringProtocol {
251253

252254
@inline(never)
253255
public func run _LessStringSubstringGenericStringProtocol(_ N: Int) {
254-
let (a, b) = equivalentWithDistinctBuffers()
256+
let (a, b) = (s1, ss1)
255257
for _ in 1...N*500 {
256258
checkLess(a, b)
257259
}
258260
}
259261

260262
@inline(never)
261263
public func run _LessSubstringStringGenericStringProtocol(_ N: Int) {
262-
let (a, b) = equivalentWithDistinctBuffers()
264+
let (a, b) = (s1, ss1)
263265
for _ in 1...N*500 {
264266
checkLess(b, a)
265267
}
266268
}
267269

268270
@inline(never)
269271
public func run _LessSubstringSubstringGenericStringProtocol(_ N: Int) {
270-
let (_, a) = equivalentWithDistinctBuffers()
271-
let (_, b) = equivalentWithDistinctBuffers()
272+
let (_, a) = (s1, ss1)
273+
let (_, b) = (s2, ss2)
272274
for _ in 1...N*500 {
273275
checkLess(a, b)
274276
}

0 commit comments

Comments
 (0)