Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
Chrome 73
Linux
Desktop
5 years ago
Test name Executions per second
for 215210.2 Ops/sec
map, filter, reduce 93797.0 Ops/sec
forEach 192245.3 Ops/sec
map 129149.3 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);