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. -- Posted via http://www.ruby-forum.com/.
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.> 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. >
njmacinnes@gmail.com
2006-Apr-26 01:10 UTC
[Rails] Re: millisecond precision over internet
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 On 26/04/06, Benigno Uria <benikk@gmail.com> wrote:> 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. > > 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. > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
njmacinnes@gmail.com 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.> > <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.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... -- Alex
njmacinnes@gmail.com
2006-Apr-26 03:07 UTC
[Rails] Re: millisecond precision over internet
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> On 26/04/06, Alex Young <alex@blackkettle.org> wrote:> njmacinnes@gmail.com 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. > > > > > <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. > 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... > > -- > Alex > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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 On 4/26/06, aqaudhere <aquadhere@gmail.com> wrote:> > 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. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060426/2cb17e04/attachment.html