Thursday, December 3, 2009

Objective C in-code profiling

To check how long something is running in objective C:

1) Declare an NSDate and set it to [NSDate date]
2) Run the code you want to test
3) Get an NSInterval from the NSDate by sending the timeIntervalSinceNow message

So for example:

NSDate* date = [NSDate date];
//RUN some expensive code her
NSTimeInterval interval = [date timeIntervalSinceNow];
NSLog(@"Time running expensive code: %f", interval);

No comments: