Measuring Performance of a block of code
suggest change1. Synchronous methods
- (void)testPerformanceReverseString {
NSString *originalString = @"hi_my_name_is_siddharth";
[self measureBlock:^{
[self.someObject reverseString:originalString];
}];
}
2. Asynchronous methods
- (void)testPerformanceOfAsynchronousBlock {
[self measureMetrics:@[XCTPerformanceMetric_WallClockTime] automaticallyStartMeasuring:YES forBlock:^{
XCTestExpectation *expectation = [self expectationWithDescription:@"performanceTestWithResponse"];
[self.someObject doSomethingThatTakesSomeTimeWithCompletionBlock:^(NSString *result) {
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:5.0 handler:^(NSError *error) {
}];
}];
}
measureBlock:runs the block repeatedly (10 times in older XCTest) and records the average.- With
automaticallyStartMeasuring:YES, the wait for the expectation is included in the measurement. - The result is compared with earlier results and a baseline, within a configurable standard deviation.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents