473,320 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

Jun 19 '06 #1
1 2496
JRS: In article <11**********************@r2g2000cwb.googlegroups. com>,
dated Mon, 19 Jun 2006 13:37:04 remote, seen in
news:comp.lang.javascript, coop <co*************@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.
Jun 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Harag | last post by:
Hi all I think this is in the wrong group but since I don't read others much or code in java script I was wondering if anyone could help me with this small problem, as I code mostly in ASP...
2
by: Timo | last post by:
When content is transferred from a hidden IFRAME (which has fetched data from a database) to a DIV in the main document, how can a script determine that the DIV has been completely populated before...
3
by: Russell | last post by:
I have a quirky issue that I believe involves timing and only 2 hairs left to pull. I have a modal dialog that is an IFrame. The IFrame contains another window - which contains the appropriate...
5
by: Pushkar Pradhan | last post by:
I've decided to use clock() to time my routines, my code is like this: clk1 = clock(); while (n != 1000000) { mm_2r2c_2r2c_bc(&a, &b, &c); n++; } clk2 = clock(); t2 = time(NULL);...
27
by: VK | last post by:
Following the side thread about the time precision in browser at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/91b9f3fd90513161/1ea06131c63cfdf0?hl=en#doc_620f160f0cb57c8c>...
2
by: G8 | 8======D | last post by:
Does anybody know the timing accuracy of VB.Net. I remember that in VB.60, one can only trigger an event with time accuracy <10ms. How about VB.Net? Was this improved? I am making a project for...
1
by: Gary Coutts | last post by:
Hi, I need to find out the execution time of some methods. Can anyone tell what the best resolution I can except when timing routine. I really need sub millisecond accuracy. Cheers
2
by: julie.siebel | last post by:
Google apparently ate my original post to this (grr) so this'll be a bit more vague than the initial post, but...*sigh*. Javascript is not my forte, and I apologize for the acky-ness of the...
4
by: DR | last post by:
What is the best possible resolution that C# timing tests can get? milliseconds? nanoseconds?
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.