Reputation: 22045
What is the iOS equivalent of Java's System.nanoTime()?
Basically I just want a simple way to see how many milliseconds (or fractions of ms) that a function takes to execute.
Upvotes: 3
Views: 1815
Reputation: 27506
You are probably looking for CFAbsoluteTimeGetCurrent().
CFAbsoluteTime before = CFAbsoluteTimeGetCurrent();
// You code here
CFAbsoluteTime after = CFAbsoluteTimeGetCurrent();
NSLog(@"duration = %f", after - before);
Upvotes: 1
Reputation: 7693
Capture two NSDate objects, one at the start of your function and one at the end. Use timeIntervalSinceDate: to get an NSTimeInterval value back. This goes down to "sub-millisecond accuracy" according to the docs.
Upvotes: 0