Fork me on GitHub

深入理解javascript事件

使用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

image

Google Chrome 189

image

 

HTML规范,推行的延时/时间间隔的最小值是4毫秒

http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html

 

  • node中,pocess.nextTick 可以超过10万次/秒
  • requestAnimationFrame
      1. 允许60+帧/秒的速度运行动画

      2. 避免后台选项卡运行这些动画,节约CPU周期

posted on 2013-06-27 12:40  【艾伦】  阅读(653)  评论(0编辑  收藏  举报