Iteraring over valus using for loop of for-of (v4)

Revision 4 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
Foreach
data.forEach(row => {
  var columnIndex = 0;

  row.forEach((value, columnIndex) => {
    f(value);
  })
})
ready

Revisions

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