Timing accuracy in Date and/or setTimeout

C

coop

I'm trying to port a high-accuracy reaction-time gathering application
from a RTLinux C implementation into a web-avaliable implementation.
We're obviously expecting to lose some accuracy and functionality, but
I need to know exactly how much accuracy we will lose.

So-
1) How accurate and precise are the Date object and setTimeout
function? Do both work off the same clock, and if so, what is the
clock, and is it uniform across most "ordinary" platforms?

2) Is there any other clock or timing resources avaliable within
Javascript?

3) If Javascript isn't the right technology (I'm almost convinced it
isn't, but I'm a lowly undergrad so I do what the boss asks), what
technology would be better suited to:
a) Present a stimulus for a specified amount of time (say 30
ms).
b) Detect user input/keystrokes, and note how long it took for
the user to react to the stimulus in a).
(We want to be within 10ms or so.)
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Mon, 19 Jun 2006 13:37:04 remote, seen in
news:comp.lang.javascript said:
I'm trying to port a high-accuracy reaction-time gathering application
from a RTLinux C implementation into a web-avaliable implementation.
We're obviously expecting to lose some accuracy and functionality, but
I need to know exactly how much accuracy we will lose.

You should have read the newsgroup FAQ before answering; it should have
guided you towards information (see sig below, and my js-dates.htm).
So-
1) How accurate and precise are the Date object and setTimeout
function?

The precision depends on the OS/browser combination; you might get 1 ms
and you might get 55 ms. Both talk in millisecond units. The accuracy
depends on the accuracy of the relevant OS clock.
Do both work off the same clock,
Probably.

and if so, what is the
clock,

Whatever the OS provides and the browser writer chooses to use.
and is it uniform across most "ordinary" platforms?

"Ordinary" is undefined; but it's not uniform across Win98/IE4,
WinXP/IE6, and Linux/Mozilla.

2) Is there any other clock or timing resources avaliable within
Javascript?

There could be in some versions; I know of none in Web javascript. For
information on JScript running under WSH, use the Microsoft groups.
3) If Javascript isn't the right technology (I'm almost convinced it
isn't, but I'm a lowly undergrad so I do what the boss asks),

Never assume that the boss is correct (and never assume out loud that he
is wrong).
what
technology would be better suited to:
a) Present a stimulus for a specified amount of time (say 30
ms).
b) Detect user input/keystrokes, and note how long it took for
the user to react to the stimulus in a).
(We want to be within 10ms or so.)

You could do that in javascript on suitable platforms; and you could
detect at least some unsuitable platforms; but ISTM that you would not
be able to do it very reliably in the presence of a Windows-type OS.
There will always be a risk of your process getting pre-empted to
process some other event.

You may be able to get good enough results for a coder-training
exercise; but ISTM that better would be needed for publishable
scientific results.

You may be able to get "closer to the hardware" with Java.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top