for loop perf demo

JavaScript performance comparison

Revision 2 of this test case created by mistadikay

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var obj = {};
  for(var i = 0; i < 100; i = i + 1) {
    var item = {index: i};
    obj[i] = item;
  }

};
</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
for loop with call
var sum = 0;
var keys = Object.keys(obj);

function call(x){
  sum = sum + keys[x];
}

for(var x = 0; x < 100; x++){
  call(x);
}
pending…
for loop without call
var sum = 0;
var keys = Object.keys(obj);

for(var x = 0; x < 100; x++){
  sum = sum + keys[x];
}
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