Declaring variables inside loops (v23)

Revision 23 of this benchmark created by David 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 < 1; i++) {
  var x = 1, y = 2, z = {}, a = {};
}
ready
Declare outside loop
var x, y, z, a;
for (var i = 0; i < 1; i++) {
  x = 1;
  y = 2;
  z = {};
  a = {};
}
ready
Declare in a loop with multiple statements
for (var i = 0; i < 1; i++) {
  var x = 1;
  var y = 2;
  var z = {};
  var a = {};
}
ready
i outside, one statement inside
for (var i = 0; i < 1000; i++) {
  var x = 1, y = 2, z = {}, a = {};
}
ready

Revisions

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