1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Objective C - tic toc equivalent

Discussion in 'iPhone/iPad Programming' started by Car123, May 12, 2011.

  1. macrumors newbie

    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?
  2. dantastic, May 12, 2011
    Last edited: May 12, 2011

    macrumors 6502


    NSDate *start = [NSDate date];
    // doing stuff
    NSTimeInterval milliseconds = [start timeIntervalSinceNow];
  3. macrumors newbie

    thanks a lot m8.
  4. macrumors 603

    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.
  5. macrumors newbie

    ended up using CFAbsoluteTimeGetCurrent() and CFTimeInterval, works just fine for what I need :)

Share This Page