Hi Peter!

To my knowledge it's impossible to build a 100% accurate timer in JS since 
the language is asynchronous in it's nature: there's no guarantee that an 
event scheduled to occur at some point in time would execute exactly at that 
moment because there may be other pending items in the event loop.
I suggest you read 2 really good insightful articles from John Resig:
http://ejohn.org/blog/how-javascript-timers-work/
http://ejohn.org/blog/accuracy-of-javascript-time/
They explain why there is a precision issue in javascript timers and 
important difference between setTimeout and setInterval functions.

You can, however, achieve some level of precision or at least assess the 
error you get by taking the mentioned issues into account. Take a look at 
javascript benchmarks like http://jsperf.com/

I hardly doubt that your approach on contacting the server to get the time 
is viable because the network latency that will seriously affect your 
measurings is completely unpredictable.

Please correct me anyone if I am wrong.

Dmitriy.

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to