Skip to content

Commit aa34ace

Browse files
committed
Add a benchmark to test comparing equal strings
1 parent 8e32123 commit aa34ace

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

benchmark/single-source/StringTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,20 @@ public func run_StringHasSuffixUnicode(_ N: Int) {
6565
}
6666
}
6767
}
68+
69+
@inline(never)
70+
internal func compareEqual(_ str1: String, _ str2: String) -> Bool {
71+
return str1 == str2
72+
}
73+
74+
public func run_StringEqualPointerComparison(_ N: Int) {
75+
let str1 = "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. "
76+
let str2 = str1
77+
for _ in 0 ..< N {
78+
for _ in 0 ..< 100_000 {
79+
if !compareEqual(str1, str2) {
80+
CheckResults(false, "Strings should be equal")
81+
}
82+
}
83+
}
84+
}

benchmark/utils/main.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ precommitTests = [
205205
"StrComplexWalk": run_StrComplexWalk,
206206
"StrToInt": run_StrToInt,
207207
"StringBuilder": run_StringBuilder,
208+
"StringEqualPointerComparison": run_StringEqualPointerComparison,
208209
"StringInterpolation": run_StringInterpolation,
209210
"StringHasPrefix": run_StringHasPrefix,
210211
"StringHasPrefixUnicode": run_StringHasPrefixUnicode,

0 commit comments

Comments
 (0)