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 22-1.
Objective-C
- (void)testPerformanceExample {
[self measureBlock:^{
// Pass a block of code to test.
}];
}
Swift
func testPerformanceExample() {
self.measureBlock() {
// Pass a block of code to test.
}
}
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.
Measure Energy Impact with Instruments
Copyright © 2018 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2016-09-13