Objective C - tic toc equivalent

Discussion in 'iOS Programming' started by Car123, May 12, 2011.

  1. macrumors newbie

    Joined:
    Mar 1, 2011
    #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

    Joined:
    Jan 21, 2011
    #2
    Code:
    NSDate *start = [NSDate date];
    
    // doing stuff
    
    NSTimeInterval milliseconds = [start timeIntervalSinceNow];
    
     
  3. thread starter macrumors newbie

    Joined:
    Mar 1, 2011
  4. macrumors 603

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #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. thread starter macrumors newbie

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

Share This Page