compare a dec while against a for loop

JavaScript performance comparison

Test case created by Phil Glanville

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function testWhile () {
    var i = 50000, a = [];
    while ( i-- ) {
      a.push( i );
    }
  }
  
  function testWhile2 () {
    var i = 0, l = 50000, a = [];
    while ( i++ < l ) {
      a.push( i );
    }
  }
  
  function testFor () {
    var i, l = 50000, a = [];
    for ( i=0; i<l; i++ ) {
      a.push( i );
    }
  }
  
  function testFor2 () {
    var i, l = 50000, a = [];
    for ( i=l; i>0; i-- ) {
      a.push( i );
    }
  }
  
  function testFor3 () {
    var i, l = 50000, a = [];
    for ( i=l; i; i-- ) {
      a.push( i );
    }
  }

};
</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
testWhile
testWhile();
pending…
testFor
testFor();
pending…
testFor2
testFor2();
pending…
testFor3
testFor3();
pending…
testWhile2
testWhile2();
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