Iphone 在Objective-C中查找次要性能猪
为了在特定的方法中发现性能猪,我通常会这样做:Iphone 在Objective-C中查找次要性能猪,iphone,objective-c,ios,macos,debugging,Iphone,Objective C,Ios,Macos,Debugging,为了在特定的方法中发现性能猪,我通常会这样做: // Some line of code LogTimeInterval(); // Some other line of code LogTimeInterval(); // Some other line of code LogTimeInterval(); 其中LogTimeInterval定义为: void LogTimeInterval() { static NSDate *_previousDate; static N
// Some line of code
LogTimeInterval();
// Some other line of code
LogTimeInterval();
// Some other line of code
LogTimeInterval();
其中LogTimeInterval
定义为:
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;
}
这使我能够发现哪些代码行花费的时间超过了必要的时间。但是,它需要修改代码,并且在存在分支逻辑时可能会很麻烦
有没有一种最有效的方法可以对特定方法进行微观分析?试试XCode的内置分析器。在它拥有的工具中,有一个时间分析器。检查这个
有没有办法说我只想检查这个特定的方法?是的,请看一下教程。您可以仅为特定进程附加时间分析器。此外,您可能还应该检查时间分析器中的反汇编视图,以便查看按方法划分的输出。本教程提到了这一点: