Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:69.0) Gecko/20100101 Firefox/69.0
Firefox 69
Mac OS X 10.15
Desktop
5 years ago
Test name Executions per second
for 27851.8 Ops/sec
map, filter, reduce 26397.2 Ops/sec
forEach 26750.4 Ops/sec
map 27278.4 Ops/sec
Tests:
  • for

    AخA
     
        const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
        let sum = 0;
        for(let i = 0; i < arr.length; i++){
            const item = arr[i] * 3;
            if(item % 4 === 0) sum += item;
        }
        console.log(sum);    
  • map, filter, reduce

     
        const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
        const sum = arr.map(item => item * 3)
            .filter((item) => item % 4 === 0)
            .reduce((item, total) => total = total + item);
        console.log(sum);    
  • forEach

     
        const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
        let sum = 0;
        arr.forEach((item)=>{
            item = item * 3;
            if(item % 4 === 0) sum += item;
        });
        console.log(sum);    
  • map

     
        const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
        let sum = 0;
        arr.map((item)=>{
            item = item * 3;
            if(item % 4 === 0) sum += item;
        });
        console.log(sum);