1

I don't need micro or nano precision, .1 millisecond precision would suffice.

Is there a reasonably reliable way to do this? It's not a critical application, sporadic errors due to eventual CPU frequency scaling or something like that are acceptable. I just need to know if it is possible. I did some searching and was unable to find higher than millisecond precision counters except from polling Chrome's native timer constructor.

I also need to achieve it in a "cross-platform and cross-browser" way, so any solution would need to be achievable on most configs.

thanks!

/edit: Status update: I was able to rule out Javascript, Silverlight and Flash.. but what about Java applets? would it be possible to achieve .1 millisecond precision using one?

baderous
  • 121
  • 8
  • 1
    Duplicate of http://stackoverflow.com/questions/6002808/is-there-any-way-to-get-current-time-in-nanoseconds-using-javascript ? – Marcel Jackwerth Jun 01 '11 at 11:28
  • not really - It does not need to go as far as nanoseconds, not even microseconds (.1 millisecond precision would suffice); and it does not need to be in JavaScript (that's only the desirable option) – baderous Jun 01 '11 at 12:14
  • I recommend to read [this article](http://ejohn.org/blog/accuracy-of-javascript-time/) from John Resig about Javascript time accuracy... and cry :-) – Grooveek Jun 01 '11 at 11:35

2 Answers2

2

No, you won't be able to get anywhere close to millisecond precision in a consistent way across browsers.

John Resig has written a good summary on the subject. It was written in 2008, but the overall conclusions should still be valid.

Pär Wieslander
  • 28,374
  • 7
  • 55
  • 54
  • yes, I have read it before. that article is directed towards analyzing the timer's accuracy, maybe he wouldn't have gone as far as he could searching for higher precision. Since then, microsecond accuracy is already possible in Chrome. I thought maybe there would be some way to do this on other browsers too. I guess there's really no way :/ thanks! – baderous Jun 01 '11 at 12:17
  • what about using Java applets, would that be possible? – baderous Jun 01 '11 at 17:15
0

After putting some more effort into this issue, I've concluded that Java Applets (where System.nanoTime() is available, which gives me more-than-enough precision) are the best option at the moment.

The compatibility isn't ideal (at least as javascript would be), but most configs already support them, and every common config at least can support them, with a simple download.

baderous
  • 121
  • 8