Add a benchmark for CFStringInlineBuffer on bridged Strings

This commit is contained in:
David Smith
2022-03-03 17:02:06 -08:00
parent abd0582105
commit c1957a3993

View File

@@ -102,7 +102,21 @@ public let benchmarks = [
BenchmarkInfo(name: "NSStringConversion.MutableCopy.Rebridge.LongUTF8", BenchmarkInfo(name: "NSStringConversion.MutableCopy.Rebridge.LongUTF8",
runFunction: run_NSStringConversion_longNonASCII_rebridgeMutable, runFunction: run_NSStringConversion_longNonASCII_rebridgeMutable,
tags: [.validation, .api, .String, .bridging], tags: [.validation, .api, .String, .bridging],
setUpFunction: { mutableTest = "Thë qüick bröwn föx jumps over the lazy dög" } ) setUpFunction: { mutableTest = "Thë qüick bröwn föx jumps over the lazy dög" } ),
BenchmarkInfo(name: "NSStringConversion.InlineBuffer.UTF8",
runFunction: run_NSStringConversion_inlineBuffer,
tags: [.validation, .api, .String, .bridging],
setUpFunction: {
mutableTest = Array(repeating: "제10회 유니코드 국제 회의가 1997년 3월 10일부터 12일까지 독일의 마인즈에서 열립니다. 지금 등록하십시오. 이 회의에서는 업계 전반의 전문가들이 함께 모여 다음과 같은 분야를 다룹니다. - 인터넷과 유니코드, 국제화와 지역화, 운영 체제와 응용 프로그램에서 유니코드의 구현, 글꼴, 문자 배열, 다국어 컴퓨팅.세계를 향한 대화, 유니코드로 하십시오. 제10회 유니코드 국제 회의가 1997년 3월 10일부터 12일까지 독일의 마인즈에서 열립니다. 지금 등록하십시오. 이 회의에서는 업계 전반의 전문가들이 함께 모여 다음과 같은 분야를 다룹니다. 세계를 향한 대화, 유니코드로 하십시오.", count: 256).joined(separator: "")
}
),
BenchmarkInfo(name: "NSStringConversion.InlineBuffer.ASCII",
runFunction: run_NSStringConversion_inlineBuffer,
tags: [.validation, .api, .String, .bridging],
setUpFunction: {
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: "")
}
)
] ]
public func run_NSStringConversion(_ n: Int) { public func run_NSStringConversion(_ n: Int) {
@@ -227,4 +241,24 @@ public func run_NSStringConversion_longNonASCII_rebridgeMutable(_ n: Int) {
innerMutableRebridge(mutableTest, n, 300) innerMutableRebridge(mutableTest, n, 300)
} }
public func run_NSStringConversion_inlineBuffer(_ n: Int) {
withUnsafeTemporaryAllocation(
of: CFStringInlineBuffer.self,
capacity: 1
) { bufferPtr in
let buffer = bufferPtr.baseAddress!
for _ in 0 ..< n {
var result = UInt64(0)
let bridged = mutableTest as NSString as CFString
let len = CFStringGetLength(bridged)
CFStringInitInlineBuffer(bridged, buffer, CFRangeMake(0, len))
for i in 0 ..< CFStringGetLength(bridged) {
let char = CFStringGetCharacterFromInlineBuffer(buffer, i)
result += UInt64(char)
}
blackHole(result)
}
}
}
#endif #endif