使用setInterval调度
1: var fireCount = 0;
2: var start = new Date;
3: var timer = setInterval(function() {
4: if (new Date - start > 1000) {
5:
6: clearInterval(timer)
7: console.log('setInterval 1000ms运行次数' + fireCount + "次数");
8: return
9: }
10: fireCount++;
11: }, 0)
1秒钟运行次数
Safari 224
Google Chrome 189
HTML规范,推行的延时/时间间隔的最小值是4毫秒
http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html
- node中,pocess.nextTick 可以超过10万次/秒
- requestAnimationFrame
-
允许60+帧/秒的速度运行动画
-
避免后台选项卡运行这些动画,节约CPU周期