Declaring variables inside loops (v13)

Revision 13 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 sum = 0;
var items = [1, 2, 3, 4];
for (var i = 0; i < 5; i++) {
  var x = items[i];
  sum = sum + x;
}
ready
Declare outside loop
var sum = 0;
var items = [1, 2, 3, 4];
var i, x;

for (i = 0; i < 5; i++) {
  x = items[i];
  sum = sum + x;
}
ready

Revisions

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