@@ -32,6 +32,7 @@ public let ObjectiveCBridging = [
32
32
BenchmarkInfo ( name: " ObjectiveCBridgeToNSSet " , runFunction: run_ObjectiveCBridgeToNSSet, tags: [ . validation, . bridging] ) ,
33
33
BenchmarkInfo ( name: " ObjectiveCBridgeFromNSSetAnyObjectToString " , runFunction: run_ObjectiveCBridgeFromNSSetAnyObjectToString, tags: [ . validation, . bridging, . String] ) ,
34
34
BenchmarkInfo ( name: " ObjectiveCBridgeFromNSSetAnyObjectToStringForced " , runFunction: run_ObjectiveCBridgeFromNSSetAnyObjectToStringForced, tags: [ . validation, . bridging, . String, . unstable] ) ,
35
+ BenchmarkInfo ( name: " ObjectiveCBridgeFromNSDateComponents " , runFunction: run_ObjectiveCBridgeFromNSDateComponents, tags: [ . validation, . bridging] , setUpFunction: setup_dateComponents)
35
36
]
36
37
37
38
#if _runtime(_ObjC)
@@ -609,3 +610,62 @@ public func run_ObjectiveCBridgeFromNSSetAnyObjectToStringForced(_ N: Int) {
609
610
}
610
611
#endif
611
612
}
613
+
614
+ #if _runtime(_ObjC)
615
+
616
+ //translated directly from an objc part of the original testcase
617
+ @objc class DictionaryContainer : NSObject {
618
+ @objc var _dictionary : NSDictionary
619
+
620
+ //simulate an objc property being imported via bridging
621
+ @objc var dictionary : Dictionary < DateComponents , String > {
622
+ @inline ( never)
623
+ get {
624
+ return _dictionary as! Dictionary < DateComponents , String >
625
+ }
626
+ }
627
+
628
+ override init ( ) {
629
+ _dictionary = NSDictionary ( )
630
+ super. init ( )
631
+ let dict = NSMutableDictionary ( )
632
+ let calendar = NSCalendar ( calendarIdentifier: . gregorian) !
633
+ let now = Date ( )
634
+ for day in 0 ..< 36 {
635
+ let date = calendar. date ( byAdding: . day, value: - day, to: now, options: NSCalendar . Options ( ) )
636
+ let components = calendar. components ( [ . year, . month, . day] , from: date!)
637
+ dict [ components as NSDateComponents ] = " TESTING "
638
+ }
639
+ _dictionary = NSDictionary ( dictionary: dict)
640
+ }
641
+ }
642
+
643
+ var componentsContainer : DictionaryContainer ? = nil
644
+ var componentsArray : [ DateComponents ] ? = nil
645
+ #endif
646
+
647
+ public func setup_dateComponents( ) {
648
+ #if _runtime(_ObjC)
649
+ componentsContainer = DictionaryContainer ( )
650
+ let now = Date ( )
651
+ let calendar = Calendar ( identifier: . gregorian)
652
+ componentsArray = ( 0 ..< 10 ) . compactMap { ( day) -> DateComponents ? in
653
+ guard let date = calendar. date ( byAdding: . day, value: - day, to: now) else {
654
+ return nil
655
+ }
656
+
657
+ return calendar. dateComponents ( [ . year, . month, . day] , from: date)
658
+ }
659
+ #endif
660
+ }
661
+
662
+ @inline ( never)
663
+ public func run_ObjectiveCBridgeFromNSDateComponents( _ N: Int ) {
664
+ #if _runtime(_ObjC)
665
+ for _ in 0 ..< N {
666
+ for components in componentsArray! {
667
+ let _ = componentsContainer!. dictionary [ components]
668
+ }
669
+ }
670
+ #endif
671
+ }
0 commit comments