Add benchmarks for withContiguousStorageIfAvailable on bridged NSArrays (#75215)

This commit is contained in:
David Smith
2024-07-16 00:24:23 -07:00
committed by GitHub
parent 1189372a68
commit a861fc117b

View File

@@ -91,6 +91,12 @@ public let benchmarks = [
BenchmarkInfo(name: "NSArray.nonbridged.mutableCopy.objectAtIndex",
runFunction: run_RealNSArrayMutableCopyObjectAtIndex, tags: t,
setUpFunction: setup_bridgedArrays),
BenchmarkInfo(name: "NSArray.bridged.bufferAccess",
runFunction: run_BridgedNSArrayBufferAccess, tags: t,
setUpFunction: setup_bridgedArrays),
BenchmarkInfo(name: "NSArray.bridged.repeatedBufferAccess",
runFunction: run_BridgedNSArrayRepeatedBufferAccess, tags: t,
setUpFunction: setup_bridgedArrays),
]
#if _runtime(_ObjC)
@@ -814,6 +820,36 @@ public func run_BridgedNSArrayObjectAtIndex(_ n: Int) {
#endif
}
@inline(never)
public func run_BridgedNSArrayBufferAccess(_ n: Int) {
#if _runtime(_ObjC)
for _ in 0 ..< n {
for i in 0..<1000 {
let tmp = nsArray as! [NSObject]
blackHole(tmp)
blackHole(tmp.withContiguousStorageIfAvailable {
$0[0]
})
}
}
#endif
}
@inline(never)
public func run_BridgedNSArrayRepeatedBufferAccess(_ n: Int) {
#if _runtime(_ObjC)
for _ in 0 ..< n {
let tmp = nsArray as! [NSObject]
blackHole(tmp)
for i in 0..<1000 {
blackHole(tmp.withContiguousStorageIfAvailable {
$0[0]
})
}
}
#endif
}
@inline(never)
public func run_BridgedNSArrayMutableCopyObjectAtIndex(_ n: Int) {
#if _runtime(_ObjC)