Skip to content

Commit e4c51ba

Browse files
authored
Merge pull request #41659 from Catfish-Man/inline-whatfer
Add a benchmark for CFStringInlineBuffer on bridged Strings
2 parents 91410d8 + c1957a3 commit e4c51ba

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

benchmark/single-source/NSStringConversion.swift

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,21 @@ public let benchmarks = [
102102
BenchmarkInfo(name: "NSStringConversion.MutableCopy.Rebridge.LongUTF8",
103103
runFunction: run_NSStringConversion_longNonASCII_rebridgeMutable,
104104
tags: [.validation, .api, .String, .bridging],
105-
setUpFunction: { mutableTest = "Thë qüick bröwn föx jumps over the lazy dög" } )
105+
setUpFunction: { mutableTest = "Thë qüick bröwn föx jumps over the lazy dög" } ),
106+
BenchmarkInfo(name: "NSStringConversion.InlineBuffer.UTF8",
107+
runFunction: run_NSStringConversion_inlineBuffer,
108+
tags: [.validation, .api, .String, .bridging],
109+
setUpFunction: {
110+
mutableTest = Array(repeating: "제10회 유니코드 국제 회의가 1997년 3월 10일부터 12일까지 독일의 마인즈에서 열립니다. 지금 등록하십시오. 이 회의에서는 업계 전반의 전문가들이 함께 모여 다음과 같은 분야를 다룹니다. - 인터넷과 유니코드, 국제화와 지역화, 운영 체제와 응용 프로그램에서 유니코드의 구현, 글꼴, 문자 배열, 다국어 컴퓨팅.세계를 향한 대화, 유니코드로 하십시오. 제10회 유니코드 국제 회의가 1997년 3월 10일부터 12일까지 독일의 마인즈에서 열립니다. 지금 등록하십시오. 이 회의에서는 업계 전반의 전문가들이 함께 모여 다음과 같은 분야를 다룹니다. 세계를 향한 대화, 유니코드로 하십시오.", count: 256).joined(separator: "")
111+
}
112+
),
113+
BenchmarkInfo(name: "NSStringConversion.InlineBuffer.ASCII",
114+
runFunction: run_NSStringConversion_inlineBuffer,
115+
tags: [.validation, .api, .String, .bridging],
116+
setUpFunction: {
117+
mutableTest = Array(repeating: "The 10th Unicode International Conference will be held from March 10 to 12, 1997 in Mainz, Germany. Register now. The conference brings together experts from across the industry, covering areas such as: - Internet and Unicode, internationalization and localization, implementation of Unicode in operating systems and applications, fonts, character arrays, multilingual computing. Dialogue to the world, do Unicode. The 10th Unicode International Conference will be held from March 10 to 12, 1997 in Mainz, Germany. Register now. The conference brings together experts from across the industry, covering areas such as: Dialogue to the world, do it in Unicode.", count: 256).joined(separator: "")
118+
}
119+
)
106120
]
107121

108122
public func run_NSStringConversion(_ n: Int) {
@@ -227,4 +241,24 @@ public func run_NSStringConversion_longNonASCII_rebridgeMutable(_ n: Int) {
227241
innerMutableRebridge(mutableTest, n, 300)
228242
}
229243

244+
public func run_NSStringConversion_inlineBuffer(_ n: Int) {
245+
withUnsafeTemporaryAllocation(
246+
of: CFStringInlineBuffer.self,
247+
capacity: 1
248+
) { bufferPtr in
249+
let buffer = bufferPtr.baseAddress!
250+
for _ in 0 ..< n {
251+
var result = UInt64(0)
252+
let bridged = mutableTest as NSString as CFString
253+
let len = CFStringGetLength(bridged)
254+
CFStringInitInlineBuffer(bridged, buffer, CFRangeMake(0, len))
255+
for i in 0 ..< CFStringGetLength(bridged) {
256+
let char = CFStringGetCharacterFromInlineBuffer(buffer, i)
257+
result += UInt64(char)
258+
}
259+
blackHole(result)
260+
}
261+
}
262+
}
263+
230264
#endif

0 commit comments

Comments
 (0)