Performance Testing with measure block - Xcode


For performance testing, Xcode provides measure block with the help of which we can execute performance testing.

The measured block is executed ten times and the test output shows the average execution time as well as individual run times and standard deviation:

func testDateFormatterPerformance() {
  let dateFormatter = DateFormatter()
  dateFormatter.dateStyle = .long
  dateFormatter.timeStyle = .short
  
  let date = Date()
  
  measure {
    let string = dateFormatter.string(from: date)
    print(string)
  }
}

Step 0

Click on the gray button, once you’re done executing test case. It will open pop-over and show the results of those 10 executions.

Step 1


Step 2