Skip to content

Commit

Permalink
Update: js.md
Browse files Browse the repository at this point in the history
  • Loading branch information
qiilee committed Aug 13, 2024
1 parent da2ee2e commit e414002
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions content/js/js.md
Original file line number Diff line number Diff line change
Expand Up @@ -10631,8 +10631,13 @@ foo(1);*/
</details>
<b><details><summary></summary></b>
参考答案:
<b><details><summary>368. JS 中的计时器能做到精确计时吗</summary></b>
参考答案:不行,因为
1. 计算机硬件没有原子钟,无法做到精确计时
2. 操作系统的计时函数本身就有少量偏差,由于 JS 的计时器最终调用的是操作系统的函数,也就携带了这些偏差
3. 按照 W3C 的标准,浏览器实现计时器时,如果嵌套层级超过 5 层,则会带有 4 毫秒的最少时间,这样在计时时间少于 4 毫秒时又带来了偏差
4. 受事件循环的影响,计时器的回调函数只能在主线程空闲时运行,因此又带来了偏差
</details>

0 comments on commit e414002

Please sign in to comment.