ActionScript new Date() 或 getTimer() 的毫秒精度

发布于 2024-12-29 10:31:26 字数 1331 浏览 3 评论 0原文

我想测量用户的反应时间。在这个例子中,我使用的是actionscript,但概念才是真正重要的,所以如果您想显示任何代码,请随意用您选择的语言回答。

用户坐在屏幕前,屏幕上会出现一个红点。当他们看到红点时,他们按下空格键。

我的逻辑如下:使红点可见,创建一个新日期,等待空格键,创建一个新日期,使用 TimeSpan 对象。

//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;

我觉得这应该可行,但我得到了一些令人不安的价值观。下面是一个典型的结果集:

[254, 294, 296, 305, 306, 307, 308, 309, 310, 308, 312, 308, 338, 346, 364, 370, 380, 387, 395, 402, 427]

请注意,某些值很接近,并且 308 被记录了多次。所以,我的问题如下:

  1. 我的代码或我正在使用的逻辑是否存在某种缺陷?
  2. 用户能够产生重复次数的概率是多少?
  3. 如果概率很低,那么我在这里错过了什么?

我还应该注意到,我(相当意外地)收到了 12 毫秒的响应时间。我正在测试该应用程序,恰好在红点出现时按下了空格键。所以,我怀疑我的代码无法判断准确的时间,至少不能达到±12ms的精度:)。

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:

  1. Is my code, or the logic I'm using, flawed in some way?
  2. What is the probability that the user is able to produce repeat times?
  3. 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 :) .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栀子花开つ 2025-01-05 10:31:26

我认为反应时间具有某种正态分布,因此某些结果更有可能出现多次。您的反应时间从 254 到 427,即 174 种可能的不同结果。所以问题是在 x 测试中,在 x 测试中,有些内容相同的可能性有多大?因为它可能是正态分布的,所以这个值会增加。

如果您在计算机上运行它,请记住其他应用程序/线程与 CPU 交互。此外,如果您通过 USB 或 PS/2 连接(USB 设备/集线器被轮询,而 PS/2 直接连接到 IRQ),操作系统中会有一些延迟

I would suppose that reaction time have somewhat normal distribution, so it might be the case that some results are more likely to occur several times. Your reaction times are from 254 to 427, that is 174 possible different results. so question is in x tests, how likely is it that in x tests, some are the same? since it is probably normaly distributed this increases.

If you run it on your computer, then remember other applications/threads interact with the CPU. Further, some latency in the OS, and if you connect via USB or PS/2 (USB-device/hub is polled, while PS/2 is direct to the IRQ)

念﹏祤嫣 2025-01-05 10:31:26
  1. 不,逻辑看起来不错。这是一种以毫秒为单位测量时间的非常简单的方法。
  2. 事实证明,人类和计算机很少能做到毫秒级的精度。
  3. 我被绊倒的是Flash!

经过几个月的断断续续的测试,我们解决了这个问题;语言。来自 ASDOC 关于弹性计时器的信息:

不建议延迟低于 20 毫秒。定时器频率
限制为每秒 60 帧,这意味着延迟低于 16.6
毫秒会导致运行时问题。

Flash 以 60 FPS 的帧速率运行。我想这意味着,如果您尝试测量时间,并且想要精确到 16 毫秒以内,那么您就不走运了。然而,这确实解释了为什么我会看到重复值,因为“60 FPS 窗口”中的任何内容都只是在同一时间进行测量。

  1. No, the logic seems fine. This is a perfectly simple way to measure time to the ms.
  2. Turns out human beings and computers can seldom do anything to millisecond accuracy.
  3. The thing I'm tripping on is Flash!

After a few months of on and off testing, we figured out the issue; the language. From the ASDOC on the flex Timer:

A delay lower than 20 milliseconds is not recommended. Timer frequency
is limited to 60 frames per second, meaning a delay lower than 16.6
milliseconds causes runtime problems.

Flash runs with a frame rate of 60 FPS. I guess this means that if you try to measure time, and want to be accurate to less the 16 ms, you are out of luck. However this does explain why I would see repeating values, as anything in this "60 FPS window" was just being measured as the same time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文