for-of-vs-for-loop

Benchmark created by Rick Waldron on


Setup

this.vals = "x".repeat(1000).split("").map((_, i) => i);

Test runner

Ready to run.

Testing in
TestOps/sec
for-of
var collected = [];
for (var value of this.vals) {
  collected.push({ value: value });
}
collected.length = this.vals.length;

 
ready
for-loop
var collected = [];
var length = this.vals.length;
var value = 0;

for (var i = 0; i < length; i++) {
  value = this.vals[i];
  collected.push({ value: value });
}
collected.length = this.vals.length;

 
ready

Revisions

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