Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   Timing accuracy in Date and/or setTimeout (http://www.velocityreviews.com/forums/t925387-timing-accuracy-in-date-and-or-settimeout.html)

coop 06-19-2006 08:37 PM

Timing accuracy in Date and/or setTimeout
 
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.)


Dr John Stockton 06-20-2006 02:23 PM

Re: Timing accuracy in Date and/or setTimeout
 
JRS: In article <1150749424.411540.325660@r2g2000cwb.googlegroups. com>,
dated Mon, 19 Jun 2006 13:37:04 remote, seen in
news:comp.lang.javascript, coop <cooper.thompson@gmail.com> posted :

>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.


--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.


All times are GMT. The time now is 06:40 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.