Run details:
Mozilla/5.0 (Linux; Android 10; SM-G965F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Mobile Safari/537.36
Chrome Mobile 106
Android
Mobile
2 years ago
Test name Executions per second
filter 1393.1 Ops/sec
reduce 1438.6 Ops/sec
Script Preparation code:
x
 
var arr = [];
for (var i = 0; i < 1000; i++) {
  arr[i] = i;
}
function someFn(i) {
  return (i * 3 * 8 / 1200 * 0.002 / 40 * 0.2);
}
var sumForEach = 0,
  sumReduce = 0,
  sumMap = 0,
  sumFilter = 0,
  sumFor = 0;
Tests:
  • filter

     
    arr.filter(item => (sumFilter += someFn(item)));
  • reduce

     
    sumReduce = arr.reduce((lastValue, item) => {
      return sumReduce += someFn(item);
    });