Skip to content

Commit 2130ba9

Browse files
authored
Revert "[benchmark] Add interpolation; more stable builder"
1 parent 62ddb33 commit 2130ba9

File tree

3 files changed

+11
-75
lines changed

3 files changed

+11
-75
lines changed

benchmark/single-source/StringBuilder.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func buildString(_ i: String) -> String {
3939
@inline(never)
4040
public func run_StringBuilder(_ N: Int) {
4141
for _ in 1...5000*N {
42-
blackHole(buildString(getString("a")))
42+
_ = buildString(getString("a"))
4343
}
4444
}
4545

@@ -52,7 +52,7 @@ func addString(_ i: String) -> String {
5252
@inline(never)
5353
public func run_StringAdder(_ N: Int) {
5454
for _ in 1...5000*N {
55-
blackHole(addString(getString("a")))
55+
_ = addString(getString("a"))
5656
}
5757
}
5858

@@ -68,10 +68,11 @@ func buildStringUTF16(_ i: String) -> String {
6868
@inline(never)
6969
public func run_StringUTF16Builder(_ N: Int) {
7070
for _ in 1...5000*N {
71-
blackHole(buildStringUTF16(getString("a")))
71+
_ = buildStringUTF16("a")
7272
}
7373
}
7474

75+
7576
@inline(never)
7677
func buildStringLong(_ i: String) -> String {
7778
var sb = i
@@ -80,10 +81,12 @@ func buildStringLong(_ i: String) -> String {
8081
return sb
8182
}
8283

84+
85+
8386
@inline(never)
8487
public func run_StringBuilderLong(_ N: Int) {
8588
for _ in 1...5000*N {
86-
blackHole(buildStringLong(getString("👻")))
89+
_ = buildStringLong("👻")
8790
}
8891
}
8992

@@ -105,16 +108,10 @@ func buildString(
105108

106109
@inline(never)
107110
public func run_StringWordBuilder(_ N: Int) {
108-
blackHole(buildString(
109-
word: getString("bumfuzzle"),
110-
count: 50_000 * N,
111-
reservingCapacity: false))
111+
_ = buildString(word: "bumfuzzle", count: 50_000 * N, reservingCapacity: false)
112112
}
113113

114114
@inline(never)
115115
public func run_StringWordBuilderReservingCapacity(_ N: Int) {
116-
blackHole(buildString(
117-
word: getString("bumfuzzle"),
118-
count: 50_000 * N,
119-
reservingCapacity: true))
116+
_ = buildString(word: "bumfuzzle", count: 50_000 * N, reservingCapacity: true)
120117
}

benchmark/single-source/StringInterpolation.swift

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ public let StringInterpolation = BenchmarkInfo(
1616
name: "StringInterpolation",
1717
runFunction: run_StringInterpolation,
1818
tags: [.validation, .api, .String])
19-
public let StringInterpolationSmall = BenchmarkInfo(
20-
name: "StringInterpolationSmall",
21-
runFunction: run_StringInterpolationSmall,
22-
tags: [.validation, .api, .String])
23-
public let StringInterpolationManySmallSegments = BenchmarkInfo(
24-
name: "StringInterpolationManySmallSegments",
25-
runFunction: run_StringInterpolationManySmallSegments,
26-
tags: [.validation, .api, .String])
2719

2820
class RefTypePrintable : CustomStringConvertible {
2921
var description: String {
@@ -41,66 +33,15 @@ public func run_StringInterpolation(_ N: Int) {
4133
for _ in 1...100*N {
4234
var result = 0
4335
for _ in 1...reps {
44-
let s: String = getString(
45-
"\(anInt) abcdefdhijklmn \(aRefCountedObject) abcdefdhijklmn \u{01}")
36+
let s = "\(anInt) abcdefdhijklmn \(aRefCountedObject) abcdefdhijklmn \u{01}"
4637
let utf16 = s.utf16
4738

4839
// FIXME: if String is not stored as UTF-16 on this platform, then the
4940
// following operation has a non-trivial cost and needs to be replaced
5041
// with an operation on the native storage type.
51-
result = result &+ Int(utf16.last!)
52-
blackHole(s)
53-
}
54-
CheckResults(result == refResult)
55-
}
56-
}
57-
58-
@inline(never)
59-
public func run_StringInterpolationSmall(_ N: Int) {
60-
let reps = 100
61-
let refResult = reps
62-
let anInt: Int64 = 0x42
63-
64-
for _ in 1...100*N {
65-
var result = 0
66-
for _ in 1...reps {
67-
let s: String = getString(
68-
"\(getString("int")): \(anInt) \(getString("abc")) \u{01}")
69-
result = result &+ Int(s.utf8.last!)
70-
blackHole(s)
42+
result = result &+ Int(utf16[utf16.index(before: utf16.endIndex)])
7143
}
7244
CheckResults(result == refResult)
7345
}
7446
}
7547

76-
@inline(never)
77-
public func run_StringInterpolationManySmallSegments(_ N: Int) {
78-
let numHex: UInt = min(UInt(N), 0x0FFF_FFFF_FFFF_FFFF)
79-
let numOct: UInt = min(UInt(N), 0x0000_03FF_FFFF_FFFF)
80-
let numBin: UInt = min(UInt(N), 0x7FFF)
81-
let segments = [
82-
"abc",
83-
String(numHex, radix: 16),
84-
"0123456789",
85-
String(Double.pi/2),
86-
"*barely* small!",
87-
String(numOct, radix: 8),
88-
"",
89-
String(numBin, radix: 2),
90-
]
91-
assert(segments.count == 8)
92-
93-
func getSegment(_ i: Int) -> String {
94-
return getString(segments[i])
95-
}
96-
97-
let reps = 100
98-
for _ in 1...100*N {
99-
for _ in 1...reps {
100-
blackHole("""
101-
\(getSegment(0)) \(getSegment(1))/\(getSegment(2))_\(getSegment(3))
102-
\(getSegment(4)) \(getSegment(5)), \(getSegment(6))~~\(getSegment(7))
103-
""")
104-
}
105-
}
106-
}

benchmark/utils/main.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,6 @@ registerBenchmark(StringComparison)
276276
registerBenchmark(StringEdits)
277277
registerBenchmark(StringEnum)
278278
registerBenchmark(StringInterpolation)
279-
registerBenchmark(StringInterpolationSmall)
280-
registerBenchmark(StringInterpolationManySmallSegments)
281279
registerBenchmark(StringMatch)
282280
registerBenchmark(StringRemoveDupes)
283281
registerBenchmark(StringTests)

0 commit comments

Comments
 (0)