Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
Chrome 87
Linux
Desktop
4 years ago
Test name Executions per second
foreach 10864.6 Ops/sec
for 5445.9 Ops/sec
map 9812.1 Ops/sec
for of 11551.4 Ops/sec
Script Preparation code:
AخA
 
   var arr = [];
    for (var i = 0; i < 1000; i++) {
      arr[i] = i;
    }
  
    function someFn(i) {
      return i * 3 * 8;
    }
Tests:
  • foreach

     
    arr.forEach(function (item){
      someFn(item);
    })
  • for

     
    for (var i = 0, len = arr.length; i < len; i++) {
      someFn(arr[i]);
    }
  • map

     
    arr.map(item => someFn(item))
  • for of

     
    for (let i of arr) {
      someFn(i);
    }