I'd like to measure the reaction time of a user. In this example, I'm using actionscript, but the concept is really what is important, so feel free to answer in your language of choice, if you want to show any code.
The user sits in front of a screen and will be presented with a red dot. When they see the red dot, they hit the space bar.
My logic is as follows: make red dot visible, create a new date, wait for spacebar, create a new date, find the difference in milliseconds using a TimeSpan object.
//listen for the keystroke
this.systemManager.stage.addEventListener(KeyboardEvent.KEY_DOWN, catchSpace, true, 1);
...
if (e.keyCode == Keyboard.SPACE) {
e.preventDefault();
this.dispatchEvent(new PvtEvent(PvtEvent.BTN_CLICK));
}
//show the red dot, making note of the time
redDot.visible = true;
this.startCount=new Date();
//user clicks the space bar
this.endCount=new Date();
var timeSpan:Number=TimeSpan.fromDates(this.startCount, this.endCount).totalMilliseconds;
I feel like this should work, but I'm getting some values that are disconcerting. Here is a typical result set:
[254, 294, 296, 305, 306, 307, 308, 309, 310, 308, 312, 308, 338, 346, 364, 370, 380, 387, 395, 402, 427]
Notice that some of the values are close, and 308 is recorded multiple times. So, my questions are as follows:
- Is my code, or the logic I'm using, flawed in some way?
- What is the probability that the user is able to produce repeat times?
- If the probability is low, then what am I missing here?
I should also note that I have (quite accidentally) received a 12ms response time. I was testing the app, and happen to hit the space bar just as the red dot appeared. So, I am doubting that my code cannot judge accurate time, at least to an accuracy of ±12ms :) .