Declaring variables inside loops (v12)

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

Revisions

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