Millisecond precision over internet


#1

Hi,

I’m new to programming and ruby and ROR, but I’m hoping to learn ruby to
create custom scientific software.

Mainly it involves measuring people’s reaction time to a series of
words.

I’m positive that this is possible using plain ruby on a computer (cause
this is BASIC territory right?). But I want to create a ROR app that can
do the same thing. My question is, is it possible to write an app that
can measure reaction time with millisecond-precision (± 1 ms), then
output a series of results to an array to be mailed back to the server?

Any help would be appreciated.

Yours,
Daisung.


#2

You will not be able to do that over the network.

I think your best bet is to measure it on the client using javascript
and then send the measurements to your server. Even using javascript I’m
not sure if you will be able to obtain the desired precision.

Cheers,

Benigno Uría.


#3

You can get millisecond precision with javascript. Try this:

The purpose of this is to measure the javascript takes to do the whole
create a new Date object, then get the timestamp from it. I kept
clicking refresh and didn’t get two different numbers once after
clicking refresh about 50 times. This means javascript (on my
processor at least, and I expect its the same in all modern
processors) can do all this in way less than 1 millisecond, probably
less than 0.02 milliseconds. You might ask if Javascript is any slower
with reacting to the click of a button. Well maybe it is a little, but
it certainly wouldn’t get anywhere near half a millisecond.

-Nathan


#4

removed_email_address@domain.invalid wrote:

You can get millisecond precision with javascript. Try this:
I don’t doubt that. I do doubt that you can get anything close to
millisecond accuracy.

The purpose of this is to measure the javascript takes to do the whole
create a new Date object, then get the timestamp from it. I kept
clicking refresh and didn’t get two different numbers once after
clicking refresh about 50 times. This means javascript (on my
processor at least, and I expect its the same in all modern
processors) can do all this in way less than 1 millisecond, probably
less than 0.02 milliseconds. You might ask if Javascript is any slower
with reacting to the click of a button. Well maybe it is a little, but
it certainly wouldn’t get anywhere near half a millisecond.
Really? What guarantees that? There’s a hell of a lot of stages
between the hardware interrupt and the browser event reaching user code,
even before taking into account the MSN messenger sitting in the system
tray that just happens to grab the processor at the wrong moment…


#5

Well, ok, nothing guarantees it. I managed to devise a test which
proves this. It works most of the time (returns zero, which is the
ideal response), but about one in every 8 or so times on my computer,
it returns a larger number such as 15. I thought it would go wrong
less than that, and I also thought it wouldn’t be quite as wrong as
that when it did. Guess I was over-optimistic.
Please note that I’m well aware that my test doesn’t take into account
the delay of the operating system in processing a mouse click, and it
isn’t strictly true that a focus event is the same as a click event,
but this test is the best I could come up with. It records the time
when the page loads and focuses on the text box. The textbox then uses
an onfocus event handler, which records the time again, and the first
time is subtracted from the second.


#6

Hi Daisung

if ruby can be installed on the client, you could write a client
application
which does the measure locally with all possible accuracy and precision,
then have it push the informations to your RoR site (either using
webservices, rpc, smtp or ftp). Actually this client application could
be
written in anything which suits your target audience (VB, .Net, Qt,
SWT…).

This application could be packaged and available as a download from your
RoR
powered site.

hope this helps

Thibaut

LoGeek
[blog] http://www.dotnetguru2.org/tbarrere