View Full Version : Objective C - tic toc equivalent
May 12, 2011, 03:38 AM
I need to find the time that a certain block of code is taking to execute. Is there a 'tic toc' equivalent in objective C, like there is in matlab for example?
May 12, 2011, 04:35 AM
NSDate *start = [NSDate date];
// doing stuff
NSTimeInterval milliseconds = [start timeIntervalSinceNow];
May 12, 2011, 07:56 AM
thanks a lot m8.
May 12, 2011, 01:44 PM
Using mach_absolute_time() (from the <mach/mach_time.h> include) is more accurate for timing small intervals than NSDate. NSDate can get "compensated" both forwards and backwards by network time.
May 13, 2011, 10:49 AM
ended up using CFAbsoluteTimeGetCurrent() and CFTimeInterval, works just fine for what I need :)