开发者

Possibility of achieving a "higher-than millisecond" precision timer on the web (preferrably using javascript)

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

Is there a reasonably reliable way to 开发者_Go百科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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜