For/for of/for in/forEach comparison (v2)

Revision 2 of this benchmark created on


Setup

function f(x) {
    return x*x/2;
  }
  
  var data = new Array(10000);
  for (let i = 0; i < 10000; i++) {
    data[i] = new Array(100).fill(Math.Random())
  }

Test runner

Ready to run.

Testing in
TestOps/sec
Normal for loop over rows and columns
for (let i = 0; i < data; i++) {
  for (let j = 0; j < data[i]; i++) {
     f(arr[i][j]);
  }
}
ready
For of over rows and columns
for (const row of data) {
  var columnIndex = 0;

  for (const value of row) {
    f(value);
    columnIndex++;
  }
}
ready

Revisions

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