MethodTimeTracker 是一个模块,可以测量每个方法耗时。
如果您觉得您的应用工作速度略慢,并想要了解代码级别上的瓶颈在哪里,您就来到了正确的位置。
Method time tracker 对每个方法的耗时进行度量。您可以指定要测量的单个方法,或者检查类中的所有方法。
以下是对 Sample project 中所有方法进行测量得出的结果。返回值是以秒为单位的时间。
使用 CocoaPods
pod 'MethodTimeTracker'
并导入头文件
#import <NSObject+MethodTimeTracker.h>
如果您想在未设置 CocoaPods 的情况下使用 MethodTimeTracker,您可以直接下载 MethodTimeTracker 文件夹中的代码并将其添加到您的项目中。
- (instancetype)init {
...
//! with method name in String value
[self trackingMethod:@"viewDidLoad"];
//! or with method name in Selector
[self trackingMethodWithSelector:@selector(viewDidLoad)];
}
- (instancetype)init {
...
//! with method name in String value
[self trackingMethods:@[@"viewDidLoad", @"privateMethod:"]];
//! or with method name in Selector
[self trackingMethodWithSelectors:@selector(viewDidLoad), @selector(privateMethod:), nil];
}
- (instancetype)init {
...
//! measure all methods
[self trackAllMethods];
//! measure all methods and shows result log dynamically
[self trackAllMethodsShowingLogDynamically];
}
//! at a point that you want to see logs.
//! The result will be shown sorted by desc order
...
[self displayMethodTimeLogs];
...