Declaring variables inside loops (v6)

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

Revisions

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