最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

JavaScript alert() advancing system time by 12ms - Stack Overflow

programmeradmin1浏览0评论

Here's a strange one:

I was working on synchronizing a JavaScript timer with a remote server and noticed my timer (based on the Date() object) was gaining about 12ms relative to my remote server on each page refresh. I narrowed it down to the JavaScript alert() function.

I created the following test and verified with 2 synchronized clocks that my system time will advance 1 second every 83-84 page refreshes. Has anybody seen this before?

<html>
<head>
</head>
<body>
<script type="text/javascript">
  alert('hello');
</script>
</body>
</html>

I'm using IE7 on XP SP3. Please tell me I'm not just going crazy!


EDIT:

I'm really not concerned about the accuracy of javascript timers. The real issue is that the JavaScript alert() function call is advancing my actual system time by 12ms.

Here's a strange one:

I was working on synchronizing a JavaScript timer with a remote server and noticed my timer (based on the Date() object) was gaining about 12ms relative to my remote server on each page refresh. I narrowed it down to the JavaScript alert() function.

I created the following test and verified with 2 synchronized clocks that my system time will advance 1 second every 83-84 page refreshes. Has anybody seen this before?

<html>
<head>
</head>
<body>
<script type="text/javascript">
  alert('hello');
</script>
</body>
</html>

I'm using IE7 on XP SP3. Please tell me I'm not just going crazy!


EDIT:

I'm really not concerned about the accuracy of javascript timers. The real issue is that the JavaScript alert() function call is advancing my actual system time by 12ms.

Share Improve this question edited Aug 5, 2010 at 15:28 derek1284 asked Aug 5, 2010 at 14:07 derek1284derek1284 4534 silver badges7 bronze badges 14
  • 4 Try refreshing it 88 times during a lighting storm. – MooGoo Commented Aug 5, 2010 at 14:28
  • 5 Just tried this (IE7, XP SP3) and to my surprise, get the same results - system time is advanced with each alert. Not sure if it's by the same amount as the OP as I didn't count the refreshes, but it definitely advances. – Iridium Commented Aug 5, 2010 at 14:32
  • 10 How do you know it's the system clock advancing and not the rest of the universe losing time? – Jason Orendorff Commented Aug 5, 2010 at 14:39
  • 2 @Jason: Maybe the javascript alert causes my puter to approach the speed of light? – derek1284 Commented Aug 5, 2010 at 14:41
  • 4 Did you try synchronizing the clocks, and then, not really do anything, or at least browse it like you would normally do, and then testing how far they're out of sync? (You know, as a control.) – JayC Commented Apr 30, 2012 at 13:15
 |  Show 9 more ments

1 Answer 1

Reset to default 2

Well,

most likely you are crazy, since you are counting on JavaScript timers to be precise.

This explains a lot of that: http://ejohn/blog/accuracy-of-javascript-time/

发布评论

评论列表(0)

  1. 暂无评论