Declaring variables inside loops (v9)

Revision 9 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
for (var i = 0; i < 1000; i++) {
  var x = i, y = i, z = {}, a = {};
}
ready
Declare outside loop
var x, y, z, a, i;
for (i = 0; i < 1000; i++) {
  x = i;
  y = i;
  z = {};
  a = {};
}
ready
Declare in a loop with multiple statements
var x, y, z, a, i;
for (i = 0; i < 1000; i++) {
  var x = i;
  var y = i;
  var z = {};
  var a = {};
}
ready
Declare in for loop
for (var i = 0,x = 1, y = 2, z = {}, a = {};
 i < 1000; i++) {
  x = i;
  y = i;
  z = {};
  a = {};
}
ready

Revisions

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