Duration to execute code in Objectice-C

This code snippet outputs the time which is needed to execute some code.

- (void)someAction {

  // save current time
  CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();

  [self someAwesomeAlgorithm];

  // print time difference to console
  // output Example: Took 0.000078 seconds.
  NSLog(@"Took %f seconds.", (CFAbsoluteTimeGetCurrent()-startTime));
}
Share

Leave a Comment