Skip to content

Commit 9cbed94

Browse files
committed
Add reverse-bridging benchmarks for array subscripting
1 parent a2e0d08 commit 9cbed94

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

benchmark/single-source/ObjectiveCBridging.swift

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ public let ObjectiveCBridging = [
7979
BenchmarkInfo(name: "UnicodeStringFromCodable",
8080
runFunction: run_UnicodeStringFromCodable, tags: ts,
8181
setUpFunction: setup_UnicodeStringFromCodable),
82+
BenchmarkInfo(name: "NSArray.bridged.objectAtIndex",
83+
runFunction: run_BridgedNSArrayObjectAtIndex, tags: t,
84+
setUpFunction: setup_bridgedArrays),
85+
BenchmarkInfo(name: "NSArray.bridged.mutableCopy.objectAtIndex",
86+
runFunction: run_BridgedNSArrayMutableCopyObjectAtIndex, tags: t,
87+
setUpFunction: setup_bridgedArrays),
88+
BenchmarkInfo(name: "NSArray.nonbridged.objectAtIndex",
89+
runFunction: run_RealNSArrayObjectAtIndex, tags: t,
90+
setUpFunction: setup_bridgedArrays),
91+
BenchmarkInfo(name: "NSArray.nonbridged.mutableCopy.objectAtIndex",
92+
runFunction: run_RealNSArrayMutableCopyObjectAtIndex, tags: t,
93+
setUpFunction: setup_bridgedArrays),
8294
]
8395

8496
#if _runtime(_ObjC)
@@ -773,3 +785,65 @@ public func run_UnicodeStringFromCodable(_ N: Int) {
773785
}
774786
#endif
775787
}
788+
789+
#if _runtime(_ObjC)
790+
var bridgedArray:NSArray! = nil
791+
var bridgedArrayMutableCopy:NSMutableArray! = nil
792+
var nsArray:NSArray! = nil
793+
var nsArrayMutableCopy:NSMutableArray! = nil
794+
#endif
795+
796+
public func setup_bridgedArrays() {
797+
#if _runtime(_ObjC)
798+
var arr = Array(repeating: NSObject(), count: 100) as [AnyObject]
799+
bridgedArray = arr as NSArray
800+
bridgedArrayMutableCopy = (bridgedArray.mutableCopy() as! NSMutableArray)
801+
nsArray = NSArray(objects: &arr, count: 100)
802+
nsArrayMutableCopy = (nsArray.mutableCopy() as! NSMutableArray)
803+
#endif
804+
}
805+
806+
@inline(never)
807+
public func run_BridgedNSArrayObjectAtIndex(_ N: Int) {
808+
#if _runtime(_ObjC)
809+
for _ in 0 ..< N * 50 {
810+
for i in 0..<100 {
811+
blackHole(bridgedArray[i])
812+
}
813+
}
814+
#endif
815+
}
816+
817+
@inline(never)
818+
public func run_BridgedNSArrayMutableCopyObjectAtIndex(_ N: Int) {
819+
#if _runtime(_ObjC)
820+
for _ in 0 ..< N * 100 {
821+
for i in 0..<100 {
822+
blackHole(bridgedArrayMutableCopy[i])
823+
}
824+
}
825+
#endif
826+
}
827+
828+
@inline(never)
829+
public func run_RealNSArrayObjectAtIndex(_ N: Int) {
830+
#if _runtime(_ObjC)
831+
for _ in 0 ..< N * 100 {
832+
for i in 0..<100 {
833+
blackHole(nsArray[i])
834+
}
835+
}
836+
#endif
837+
}
838+
839+
@inline(never)
840+
public func run_RealNSArrayMutableCopyObjectAtIndex(_ N: Int) {
841+
#if _runtime(_ObjC)
842+
for _ in 0 ..< N * 100 {
843+
for i in 0..<100 {
844+
blackHole(nsArrayMutableCopy[i])
845+
}
846+
}
847+
#endif
848+
}
849+

0 commit comments

Comments
 (0)