I'm trying to calculate (in milliseconds) how much time went by while completing operations in my app. I've read through most of the documentation and looked through examples, although my app seems to crash near the NSLog function. All of the answers addressed here seem to be specifically for iOS, and I'm trying to get this working with OSX. Any help or suggestions would be appreciated — thank you.
- (void)someMethod {
NSTimeInterval startTime = [[NSDate date] timeIntervalSinceReferenceDate];
// Do something else
// Now see how much time went by
NSTimeInterval endTime = [[NSDate date] timeIntervalSinceReferenceDate];
double elapsedTime = startTime - endTime;
NSLog(@"time: %@", elapsedTime);
}
Your problem is that you are trying to print an object with %@
but the time is a double. Instead you should change the last line to
NSLog(@"time: %f", elapsedTime);
Also note that startTime - endTime
give you a negative time so you should probably switch the order to get the correct duration.