3

How to calculate the time taken to load a view/window? This can be done by this:

NSDate *startTime=[NSDate date];

//some code to load another window from winController

NSDate *endTime=[NSDate date];
NSTimeInterval diff = [endTime timeIntervalSinceDate:startTime];
NSLog(@"Time to load is %f seconds.\n\n\n",diff);

But it will not calculate the total and exact time taken. To load a window, and then in init and awakeFromNib it asynchronously calls services, loads custom views, populates tableviews etc, and which is spread on dozens of classes/controllers and scores of methods.

If I use the above(program shown), the endTime is reached while spinner continues to spin and service calls are in progress.

I can check by watching Clock that it takes more than a minute to load the window, and to ready to perform any action on it, but diff is calculates to 0.5 seconds something.

Now the problem is that I can not change the whole code of project, however I can insert few things in between.

How to do this, suggestions will be appreciated.

4

1 回答 1

0

我知道这已经晚了,不确定您是否仍在寻找答案(但其他人可能正在寻找类似问题的解决方案)。但在这种情况下,您必须跟踪您的代码,即您需要知道哪个您的异步调用的回调在最后被调用。这很容易追踪。我通常做的是非常普通和简单的,将 NSLog(%@"1​​")... NSLog(%@"any_number") 放在那些回调中。并检查最后打印的内容。这样你就可以将你的 endtimer 代码放在那个回调中,并知道加载你的窗口需要多少时间。希望这可以帮助某人。

于 2013-04-18T08:01:31.253 回答