The Set isSubsetOf method performance decrease in Xcode 7-beta5

Originator:konstantin.koval1
Number:rdar://22357787 Date Originated:20-Aug-2015 09:22 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode-beta (7A176x)
Classification:Performance Reproducible:Always
 
Summary:
The isSubsetOf Set method performance has decreased dramatically in Xcode7-beta5 in comparison ti Xcode6.4 

Xcode 6.4:        0.00000046 sec
Xcode 7-beta5:    5.96 sec  

Steps to Reproduce:
- make 2 random Set<Int>
-call set.isSubsetOf(otherSet) 
- measure speed with CACurrentMediaTime

Code: 

func makeRandomSet(count: Int) -> Set<Int> {
  
  var set = Set<Int>(minimumCapacity: count)
  for _ in 0...count  {
    set.insert(Int(arc4random()))
  }
  return set
}

func measure(_ title: String? = nil, times: Int = 20, call: () -> Void) {
  var results = [CFTimeInterval]()
  for _ in 1...times {
    let startTime = CACurrentMediaTime()
    call()
    let endTime = CACurrentMediaTime()
    let time =  endTime - startTime
    results.append(time)
  }
  
  title.map { print("\($0) : ", appendNewline: false) }
  let avarage = results.reduce(0, combine: +) / Double(times)
  print("() Average - \(avarage)")
}

func test () {
  let set = makeRandomSet(5_000_000)
  let otherSet = makeRandomSet(set.count)
  
  var res: Bool = false
  
  measure("IsSubsetOf") {
    res = set.isSubsetOf(otherSet)
  }
  print(res)
}

Expected Results:
The performance should be at least the same as in old Xcode and Swift version or better.

Actual Results:
It get worse. Much worse!!!

Notes:
Test project is attached

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!