Forum: Ruby on Rails millisecond precision over internet

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
aqaudhere (Guest)
on 2006-04-26 03:45
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.
Benigno Uria (Guest)
on 2006-04-26 04:45
(Received via mailing list)
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.
unknown (Guest)
on 2006-04-26 05:13
(Received via mailing list)
You can get millisecond precision with javascript. Try this:

<script>
theDate = new Date();
now = theDate.getTime();
document.write(now + "<br />");
theDate = new Date();
now = theDate.getTime();
document.write(now + "<br />");
</script>

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
Alex Y. (Guest)
on 2006-04-26 05:38
(Received via mailing list)
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...
unknown (Guest)
on 2006-04-26 07:10
(Received via mailing list)
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.

<html>
<head>
<script>
function writeTime()
{
	theDate = new Date();
	now = theDate.getTime();
	return now;
}
</script>
</head>
<body onload="document.form1.testBox.value = writeTime();
document.form1.testBox.focus();">
<form name="form1">
<input type="text" onfocus="this.value = writeTime() - this.value;"
name="testBox" />
</form>
</body>
</html>
Thibaut Barrère (Guest)
on 2006-04-26 12:30
(Received via mailing list)
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
This topic is locked and can not be replied to.