Declaring variables inside loops (v5)

Revision 5 of this benchmark created by Ryan Patterson 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
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

Revisions

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