Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

time

iphone

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.

like image 409
willc2 Avatar asked Jul 04 '09 11:07

willc2


1 Answers

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.

like image 136
zoul Avatar answered Nov 08 '22 07:11

zoul