setTimeout vs. setInterval

JavaScript performance comparison

Revision 6 of this test case created by Gabriel R. Giannattasio

Preparation code

<script>
  window.foo = 'qux';
  
  function test1(callback) {
    window.foo = 'bar';
    callback.apply();
  }
  
  function test2(callback) {
    var i = 1000000;
    while (i--) {
      window.foo = 'bar';
    }
    callback.apply();
  }
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var callback = function() {
    deferred.resolve();
  };

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
setTimeout + fast function
// async test
setTimeout(test1, 0, callback);
pending…
setTimeout + slow function
// async test
setTimeout(test2, 0, callback);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments