Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
.map().filter() vs .reduce vs .foreach()
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0
Browser:
Firefox 147
Operating system:
Windows
Device Platform:
Desktop
Date tested:
3 months ago
Test name
Executions per second
.map().filter()
8465.0 Ops/sec
.reduce()
16780.2 Ops/sec
.forEach()
5070.1 Ops/sec
Script Preparation code:
var array = []; for (var i = 0; i < 10000; i++) { array[i] = i; } var firstTestResults = []; var secondTestResults = []; var thirdTestResults = [];
Tests:
.map().filter()
firstTestResults = array.map(value => { return value + 10; }) .filter(value => { return value % 2 === 0; });
.reduce()
secondTestResults = array.reduce((acc, value) => { value = value + 10; if (value % 2 === 0) { acc.push(value); } return acc; }, []);
.forEach()
array.forEach(value => { value = value + 10; if (value % 2 === 0) { thirdTestResults.push(value); } })