最近做一个尽量快的counter,遇到一些疑惑:为什么setTimeout的刷新率能比requestAnimationFrame高?除了setTimeout1微秒以外,还能更快的计数吗?setTimeout方式以1微秒去计数,数到1000大致花了6.5svari=0;functionloop(){if(i==1000){console.log('end');}else{doSomething();setTimeout(loop,1);}}functiondoSomething(){document.body.innerHTML=i++;}以requestAnimationFrame去数到1000,大致花了16.7s。刷新率大致是1s/60vari=0;functionstep(){if(i==1000){//16717console.log('end');}else{document.body.innerHTML=i++;requestAnimationFrame(step);}}requestAnimationFrame(step);
神不在的星期二
慕哥6287543
相关分类