Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How precise is the timer in xcode? Milliseconds?

The main question is the touch of a button on the iPad milliseconds fast?


I need to build an app for a study that records in milliseconds (with no delay), when a button is clicked. From there it will need to record the latency from the button being clicked to when an object is moved and when the "next" button is clicked. I just wanted to know how accurate the recording of the buttons being tapped is.


Basically you'd click a start button, then it would record the time until you move a piece to drag and drop it in the missing area. I would also need the time it takes when the movement starts to when you click the finish button.


User uploaded file


Any help would be great! Thanks!

Posted on May 20, 2015 12:12 PM

Reply
Question marked as Best reply

Posted on May 20, 2015 6:07 PM

Calling [[NSDate date] timeIntervalSinceNow] repeatedly gives me roughly 2^10-5 (e.g. 50 000 ticks per second).

Be aware that this doesn't include delays introduced by AppNap or other OS activity that may add 100ms delays on occasion.

4 replies

May 21, 2015 7:30 PM in response to rlzolinas

While I'm not an expert on the issue I can think of a number of possible issues.


Assuming that your doing a Objective-C/Swift app there are several places where you may introduce delays, the first is the run loop (which is typically mostly hidden to the programmer) that processes user inputs like clicks and button presses and passes these events on to the appropriate action method.


The run loop executes on the main thread so if you do any time consuming calculations do them on a separate thread instead, to avoid any delays due to time consuming app calculations.


Its also possible that the run loop may have a internal delay between registering an input and before it generates a action call for it.


The 100 ms delay I mentioned is taken from Apples 2013 World Wide Developer Conference, session 209 - "Improving Power Efficiency with AppNap" page 83 - it mentions that "Coalescing [timer] delay is on order of 100 ms. About the same as delay due to normal system load".


Having less apps running will most likely reduce length and frequency of the system delays.


You may also consider disabling AppNap on the OS or for the app, or you may choose to code the app properly so that it tells the OS about how much delay i.e. how small the timer tolerance must be.

May 22, 2015 7:16 AM in response to hokanst

Some run loop events may need time to be distinguishable from each other e.g. single vs double vs triple clicks.


Some events like dragging or key pressing will create repeating events in the order of 1 event every 0.1s.


If you need to detect events when they actually occur you may need to use more low level code to access the actual inputs rather than their more complex composite events like double clicks (1 click + a delay less than x s + 1 click).

How precise is the timer in xcode? Milliseconds?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.