Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
reduce vs map & filter
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0
Browser:
Firefox 121
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
map and filter
8360.3 Ops/sec
reduce
12799.1 Ops/sec
Script Preparation code:
var arr = []; for (var i = 0; i < 1234; i++) { const obj = {}; obj[`${i}key`] = i; arr.push(obj); } function shuffle(array) { let currentIndex = array.length, randomIndex; // While there remain elements to shuffle. while (currentIndex > 0) { // Pick a remaining element. randomIndex = Math.floor(Math.random() * currentIndex); currentIndex--; // And swap it with the current element. [array[currentIndex], array[randomIndex]] = [ array[randomIndex], array[currentIndex] ]; } return array; } shuffle(arr); var arr2 = []; for (var i = 0; i < 12345; i++) { const obj = {}; obj[`${i}key`] = i; arr2.push(obj); }
Tests:
map and filter
arr2.map((item, key) => arr[key]).filter(item => item);
reduce
arr2.reduce((acc, item, key) => {if(arr[key]){acc.push(item)}return acc;}, [])