2

我目前正在开发一个 iOS 应用程序。我需要比较在 iPhone 和/或 iPad 上启动所需的时间。有人可以建议吗?

4

2 回答 2

1

记下main()和 中的当前时间-application:didFinishLaunchingWithOptions:,然后计算差值。例子:

主.m:

// main.m

NSDate *startupDate;

int main(int argc, char **argv)
{
    NSAutoreleasePool *pool = [NSAutoreleasePool new];
    startupDate = [[NSDate alloc] init];
    int exitCode = UIApplicationMain(argc, argv, NULL, @"AppDelegate");
    [startupDate release];
    [pool drain];
    return exitCode;
}

// etc.

AppDelegate.m:

// AppDelegate.m

extern NSDate *startupDate;

- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)opts
{
    NSDate *launchFinishedDate = [[NSDate alloc] init];
    NSTimeInterval launchTimeInSeconds = [launchFinishedDate timeIntervalSinceDate:startupDate];
    [launchFinishedDate release];

    // launchTimeInSeconds will contain the launch time in seconds (floating point).
    // create UI setup etc. as usual
}
于 2012-05-01T19:22:39.560 回答
0

您可以将 Instruments(包含在 Xcode 中)与 Time Profiler 一起使用来监控您的应用程序的启动。

于 2012-05-01T23:42:51.673 回答