0

I'm trying to create a simple reaction time (RT) task in javascript, and I'd like to have roughly 1 ms resolution. I've been testing some simple code to see if the distribution of RTs looks as expected. Basically, the script uses performance.now() to grab the time as soon as a key is pressed, and it compares that time to the previous key press time. In other words, I'm getting a simple distribution of times between keypresses.

To my surprise, the distribution was binned in 8ms intervals. For instance, there were peaks at roughly 120 ms, 128 ms, 136ms, etc. (decimal values are returned since I'm using performance.now()), but there were empty gaps in between. I've seen the exact same thing whether i'm using Firefox, Chrome, or Safari. What is causing this granular timing? Is this a limitation of my operating system, or of the browsers? Is there anything I can do to stop this binning and gain millisecond resolution? If it helps, I'm running OS X El Capitan on a 2012 Macbook Pro. Thanks!

ryan
  • 1
  • you can't. javascript is not a realtime environment. – Daniel A. White Jan 31 '17 at 01:51
  • Thanks for your quick response. I'm not a programmer, so please bear with me. I'm trying to understand how my question is answered in the referenced "duplicate" question, given that I'm not using setTimeout(). Two thoughts: 1). One user from 2008 said that Windows system has a granularity of 15ms, so browsers in Windows will have that same fundamental limitation. I'm using Mac, but is this basically the same problem I'm seeing 8 years later? 2). If so, how exactly is performance.now() supposed to provide "sub-millisecond" accuracy if it is limited by this 8ms granularity? Thanks! – ryan Jan 31 '17 at 03:02

0 Answers0