Declaring variables inside loops (v10)

Revision 10 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

Test runner

Ready to run.

Testing in
TestOps/sec
Declare in a loop with one statement

var items=[1,2,3,4];
for (var i = 0; i < 5; i++) {
  var x += items[i];
}
ready
Declare outside loop
var i = 0;
var items=[1,2,3,4];
var x=0;
for (i = 0; i < 5; i++) {
  x += items[i];
}
ready
Declare in a loop with multiple statements
var i = 0;
var items=[1,2,3,4];
var x=0;
for (var i = 0; i < 5; i++) {
  x += items[i];
}
ready

Revisions

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