Response Timing on MacOS

From KubovyLab

Jump to: navigation, search

Advice from Martin van den Berg:

First, I use a USB keyboard, instead of a keyboard that is connected to the serial port. Of course on a Mac the serial port is an ancient memory, and I think it was called the ADB port. But that port was indeed sampled only every 11 milliseconds. The USB port has a much higher sampling rate, making it possible to detect key presses with much greater temporal precision.

Then, when in the experiment it's time to get a response, I simply enter a "while" loop, and I sit there until a key is pressed (or, while a key is not pressed). Doing it that way makes the program able to detect, in principle, key presses as quickly as it can go through cycles of the while loop, which is definitely more than once per millisecond on a somewhat modern computer. On a 400MHz G3 I could already get better than millisecond precision that way.

The timer is then the final problem there. I get a time before I start the "while" response sampling loop and after that loop exits, then I look at the difference between these two to determine response time. On the Mac the system clock can be polled in various ways, and some of those ways have millisecond precision. I don't know what it's like on other platforms.

To empirically determine what the precision is of my timing I have done the following. Run the response while loop over and over again, say 1000 times in a for loop. And while that is running, keep a key on the keyboard pressed and record the duration of every while loop. Then take the difference in duration of successive while loops. Doing that you can find the following:

  1. All differences are 0. This means that your keyboard sampling is very fast but the timer is not very precise and can't keep up with the keyboard sampling.
  2. All differences are roughly the same and around 10 to 18 milliseconds. The keyboard sampling is very slow. Your timer may be slow too, but it can keep up with the slow keyboard sampling. In that case all differences are very similar, say, all 10 milliseconds. Or, all differences are roughly the same, say, between 8 and 11 milliseconds. That would be an indication that the timer is at least more precise than the keyboard sampling, and it can measure the random fluctuations.
  3. All differences are roughly the same and very small, say, around 1 millisecond. This is the ideal case. Both the keyboard sampling and the timer are fast.
Personal tools