How to access system time finer than 1 second on the iPhone

iphone, time

Solution

See CFAbsoluteTimeGetCurrent:

CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
// do something you want to measure
CFAbsoluteTime end = CFAbsoluteTimeGetCurrent();
NSLog(@"operation took %2.5f seconds", end-start);

Should you find `CFAbsouteTime` too verbose, you can simply use `double` instead.

Problem

The system time function time(0) gives me a resolution of 1 second, right? Is there a finer-grained function? I'm using it to determine the time interval between two events. A line of code would help me greatly. It makes it easier to have something concrete to hang the concept on when I look in the official documentation.

Original source