找出我的方法执行的时间

时间:2012-10-10 11:07:06

标签: objective-c profiling

如何找出我的哪些方法花费最多时间在我的iPad应用程序中执行?

2 个答案:

答案 0 :(得分:1)

NSLog放在方法的开头,将一个放在最后

控制台显示NSLog的确切时间,以便您可以确定哪个占用日志时间

示例:

-(void)buttonsTag{
  NSLog(@"Beginning of buttonsTag Method");
  btn1.tag  =1;
  btn2.tag  =2;
  btn3.tag  =3;
  btn4.tag  =4;
  btn5.tag  =5;
  btn6.tag  =6; 
  btn7.tag  =7;
  btn8.tag  =8;
  btn9.tag  =9;
  btn10.tag =10;

  NSLog(@"End of buttonsTag Method");

}


 //The console output:
 //2012-10-10 14:22:29.308 APP[3691:c07] Beginning of buttonsTag Method
 //2012-10-10 14:22:29.309 APP[3691:c07] End of buttonsTag Method
 //The deference is 14:22:29.309 - 14:22:29.308 = 00:00:00.001

答案 1 :(得分:1)

为了更好的CPU分析,您应该在XCode Instruments中使用Time profiler。

参考http://cocoaforbreakfast.wordpress.com/2011/03/01/time-profiler-when-a-small-change-can-bring-huge-gains/