Timing accuracy in Date and/or setTimeout

Discussion in 'Javascript' started by coop, Jun 19, 2006.

  1. coop

    coop Guest

    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.)
    coop, Jun 19, 2006
    #1
    1. Advertising

  2. JRS: In article <>,
    dated Mon, 19 Jun 2006 13:37:04 remote, seen in
    news:comp.lang.javascript, coop <> 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.
    Dr John Stockton, Jun 20, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Q2hhcmxlc0E=?=

    Accuracy and CSS

    =?Utf-8?B?Q2hhcmxlc0E=?=, Jan 16, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    657
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,229
    Michael Borgwardt
    May 30, 2004
  3. PercyP
    Replies:
    5
    Views:
    547
    PercyP
    Oct 20, 2004
  4. aurora
    Replies:
    3
    Views:
    386
    aurora
    Feb 2, 2005
  5. Mr Fish
    Replies:
    5
    Views:
    565
    Karl Heinz Buchegger
    Oct 21, 2005
Loading...

Share This Page