Skip to content

Commit 1a0cd33

Browse files
committed
[Benchmark] Shortened local var lifetime.
1 parent 7c1c9ce commit 1a0cd33

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

benchmark/single-source/SubstringTest.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,23 @@ public func run_SubstringFromLongStringGeneric(_ n: Int) {
6363
}
6464
}
6565

66-
@inline(never)
67-
public func run_StringFromLongWholeSubstring(_ n: Int) {
66+
private func getLongWideRealBuffer() -> String {
6867
var s0 = longWide
6968
s0 += "!" // ensure the string has a real buffer
70-
let s = Substring(s0)
69+
return s0
70+
}
71+
72+
@inline(never)
73+
public func run_StringFromLongWholeSubstring(_ n: Int) {
74+
let s = Substring(getLongWideRealBuffer())
7175
for _ in 1...n*500 {
7276
blackHole(String(s))
7377
}
7478
}
7579

7680
@inline(never)
7781
public func run_StringFromLongWholeSubstringGeneric(_ n: Int) {
78-
var s0 = longWide
79-
s0 += "!" // ensure the string has a real buffer
80-
let s = Substring(s0)
82+
let s = Substring(getLongWideRealBuffer())
8183
for _ in 1...n*500 {
8284
create(String.self, from: s)
8385
}

0 commit comments

Comments
 (0)