Declaring variables inside loops (v17)

Revision 17 of this benchmark created on


Description

Tests whether declaring a variable inside a loop, rather than declaring outside and just assigning values, is more performant

Setup

var testarray=[];
    
    for (var i = 0; i < 10000; i++) {
      testarray[i]=i+"aa"+i;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Declare inside loop
var len = testarray.length;
for (var i = 0; i < len; i++) {
  var x = 1;
}
ready
Declare outside loop
for (var i = 0; i < testarray.length; i++) {
  var x = 1;
}
ready

Revisions

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