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

    #1
    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

    dantastic

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

    #3
    thanks a lot m8.
     
  4. macrumors 603

    #4
    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

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

Share This Page