如何查看iPhone应用程序启动所需的时间?

时间:2012-05-01 19:14:27

标签: iphone ipad ios5

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

2 个答案:

答案 0 :(得分:1)

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

的main.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
}

答案 1 :(得分:0)

您可以使用仪器(包含在Xcode中)和Time Profiler来监控您的应用程序的启动。