Declaring variables inside loops

JavaScript performance comparison

Revision 11 of this test case created by

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
Declare in a loop with one statement
var sum;
var items=[1,2,3,4];
for (var i = 0; i < 5; i++) {
  var x = items[i];
  sum =sum + x;
}
pending…
Declare outside loop
var i = 0;
var items=[1,2,3,4];
var x=0;
var sum=0;
for (i = 0; i < 5; i++) {
  x=items[i];
  sum =sum+x;
}
pending…
Declare in a loop with multiple statements
var i = 0;
var items=[1,2,3,4];
var x=0;
var sum=0;
for (var i = 0; i < 5; i++) {
  sum += items[i];
}
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