Declare variable inside loop or outside - Performance

JavaScript performance comparison

Revision 92 of this test case created by

Preparation code

<script>
  Benchmark.prototype.setup = function() {
  };
</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
loop
var x;
var i;
for(i=0;i<1000;i++){
    x=i+1234;
}
pending…
loop 1
for(var i=0;i<1000;i++){
    var x=i+1234;
}
pending…
loop 2
var x;
for(var i=0;i<1000;i++){
    x=i+1234;
}
pending…
loop 3
var x;
for(var i=0;i<1000;i++){
    x=new Array();
}
pending…
loop 4
var x;
for(var i=0;i<1000;i++){
    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