To discover perfomance hogs in a specific method I often do something like this:
// Some line of code
LogTimeInterval();
// Some other line of code
LogTimeInterval();
// Some other line of code
LogTimeInterval();
Where LogTimeInterval is defined as:
void LogTimeInterval()
{
static NSDate *_previousDate;
static NSInteger _counter = 0;
NSDate *date = [NSDate date];
if (!_previousDate) {
_previousDate = date;
}
NSLog(@"LINE %d: %f", _counter++, [_previousDate timeIntervalSinceDate:date]);
_previousDate = date;
}
This allows me to discover which lines of code are taking more time than necessary. However, it requires modifying the code and can be cumbersome when there is branching logic.
Is there a most efficient way to do this micro-level analysis for a specific method?
Try XCode’s built-in Profiler. Among the tools it has, there is a time profiler. Check this link for a nice tutorial on how to use it