Test name | Executions per second |
---|---|
filter | 1393.1 Ops/sec |
reduce | 1438.6 Ops/sec |
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;
arr.filter(item => (sumFilter += someFn(item)));
sumReduce = arr.reduce((lastValue, item) => {
return sumReduce += someFn(item);
});