Documentation Archive

Developer

Energy Efficiency Guide for Mac Apps

Test Performance

Performance testing identifies regressions in your code that may result in greater than expected energy usage. A performance test takes a block of your code and runs it ten times consecutively. Each time a run occurs, the test captures the execution time and standard deviation of the run. The results are then combined to form a baseline for comparison.

Performance testing uses the XCTest framework. In your test method, call measureBlock:, and pass it the block of code you want to measure, as shown in Listing 19-1.

Listing 19-1An XCTest performance test

Objective-C

  1. - (void)testPerformanceExample {
  2. [self measureBlock:^{
  3. // Pass a block of code to test.
  4. }];
  5. }

Swift

  1. func testPerformanceExample() {
  2. measureBlock() {
  3. // Pass a block of code to test.
  4. }
  5. }

Performance test results are accessible for analysis throughout Xcode—in the report navigator, the issues navigator, and the source editor. For more information on performance testing, see Writing Performance Tests in Testing with Xcode.