使用 Javascript 捕获反应时间,准确性问题 [英] Capturing reaction times using Javascript, accuracy concerns

查看:22
本文介绍了使用 Javascript 捕获反应时间,准确性问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个点探测任务(人们必须在图像消失后迅速对一个点做出反应),我们需要测量反应时间并显示用于在线治疗研究的预定义间隔的刺激.

我们已经决定使用 Javascript,我们愿意对用户施加一些限制,即排除 IE 等.但我们不能完全禁止 Windows.

我阅读了 John Resig 的帖子关于该主题并根据此我们必须禁止 Windows 上的所有浏览器,但 Firefox 和 Chrome 除外.

另外这个答案 建议使用 console.time(); 作为 FF 和 Chrome 的最佳实践.

我有一些后续问题,考虑到 Resig 的帖子现在已经有 4 年历史了,而且上面的问题是关于测量函数执行时间的(这意味着代码倾斜计时器的执行是好的,不像我们的例子那样糟糕)) 而不是反应时间研究.

以下类似问题 只是要求最好的网络语言",但只收到了使用 JS 的全面推荐(这是一些已发表的研究所做的,但他们没有发布技术细节).

  1. 我们能否以某种方式使用 console.time() 的更高准确性?我认为不会,因为它只返回到控制台,即无法在变量中捕获.
  2. 在过去 4 年中,计时准确性是否有任何重大变化?出于多种原因,我很乐意禁止 IE,但也许 Windows 上的 Safari 和 Opera 的情况发生了变化?
  3. 我是否应该使用第二种方法来与执行过程相关联 获得另一组时间进行比较/交叉验证?

解决方案

ObDisclaimer - 我曾经为大学研究部门编写这样的软件.

您可以使用 performance.now()(或 performance.webkitNow(),具体取决于浏览器版本)来获得比 Date 更准确的时间戳.现在().请参阅此处了解更多信息.

但是需要考虑的一个问题是屏幕刷新.假设刷新率为 60 Hz,图像实际出现在屏幕上的时间可能会有 16 毫秒的差异,具体取决于:

  1. 软件是否与屏幕刷新率同步(在 JS、AFAIK 中不可能),以及
  2. 图像和点探针相对于屏幕顶部的位置 - 在屏幕顶部绘制的像素在其下方绘制之前.

您还应该考虑键盘扫描间隔等因素造成的影响.在一个项目中,研究人员发现在(从记忆中,这是 20 年前)大约 30 毫秒的时间段内有重要分组,这似乎是由于在 Psion PDA 上扫描键盘按键的频率是用于测试.

在这种情况下,我通过使用 PIC 微控制器构建一个硬件按钮盒"解决了这个问题,该微控制器可以以 9600 bps 的速度发送串行字节而没有扫描延迟,并且 <2ms 将按键从盒子发送到掌上电脑.

我正在考虑写一篇关于屏幕刷新问题的论文.然后我找到了一份真正的工作 ;-) 我不知道有没有其他人研究过它.

I'm building a dot probe task (people have to react quickly to a dot after an image disappears) and we need to measure reaction times and show stimuli for pre-defined intervals for usage in an online therapy study.

We already decided on Javascript and we're willing to impose some constraints on users, i.e. ruling out IE etc. We can't ban Windows completely though.

I read John Resig's post on the topic and according to this we'll have to ban every browser on Windows except Firefox and Chrome.

In addition this answer advises using console.time(); as best-practice for FF and Chrome.

I have some follow-up questions, considering that Resig's post is 4 years old now and that the question above is about measuring function execution time (that means the execution of code skewing the timer is good, not bad as in our case) and not about a reaction time study.

The following similar question just asked for the "best web language" and only received the blanket recommendation to use JS (which is what a couple of published studies have done, but they don't publish technical details).

  1. Can we somehow use the better accuracy of console.time() where available? I think not, because it only returns to the console, i.e. it can't be captured in a variable.
  2. Have there been any significant changes to timing accuracy in the last 4 years? I'm comfortable banning IE for many reasons, but maybe things have changed for Safari and Opera on Windows?
  3. Should I use a second method that ties into the execution process to get another set of times for comparison / cross-validation?

解决方案

ObDisclaimer - I used to write software just like like this for a University research department.

You can use performance.now() (or performance.webkitNow(), depending on browser version) to get a more accurate timestamp than Date.now(). See here for more information.

One issue to take into account however is screen refresh. Assuming a 60 Hz refresh rate, there can be a 16 ms variance in when the image actually appears on screen, depending on:

  1. whether the software is synched to the screen refresh rate (not possible in JS, AFAIK), and
  2. where the image and dot probe are relative to the top of the screen - pixels drawn at the top of the screen are drawn before those below them.

You should also consider effects caused by things like keyboard scanning intervals. On one project the researcher found significant groupings around periods that were (from memory, this is 20 years ago) a multiple of 30ms or so, which appeared to be due to how frequently the keyboard was being scanned for key presses on the Psion PDA being used for the tests.

In this case I solved the problem by building a hardware "button box" using a PIC microcontroller which could send a serial byte at 9600 bps with no scanning latency, and <2ms to get the key press from the box to the PDA.

I was considering writing a paper about the issues around screen refresh. Then I got a real job ;-) I don't know if anyone else ever studied it.

这篇关于使用 Javascript 捕获反应时间,准确性问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆