Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Reduce vs Flatmap 10000 items
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Mobile Safari/537.36
Browser:
Chrome Mobile 126
Operating system:
Android
Device Platform:
Mobile
Date tested:
one year ago
Test name
Executions per second
Reduce
0.4 Ops/sec
Flatmap
167.9 Ops/sec
Script Preparation code:
let id = 0 function generateId() { id = id + 1 return id } function generateOject(id) { changes = [] for (let i = 0; i < 10; i++) { changes.push({ id, oldValue: i * 10, newValue: i * 20 }) } return { id, name: `Object#${id}`, changes } } window.lookup = {}; for (let i = 0; i < 10000 ; i++) { window.lookup[generateId()] = generateOject(); }
Tests:
Reduce
const uniqNodes = new Set(); const changes = Object.values(window.lookup).reduce((changes, node) => { if (!uniqNodes.has(node)) { uniqNodes.add(node); return changes.concat(node.changes) } return changes }, []);
Flatmap
const uniqNodes = new Set(); Object.entries(window.lookup).forEach(([_identifier, node]) => { if (!uniqNodes.has(node)) { uniqNodes.add(node); } }); const changes = Array.from(uniqNodes).flatMap(node => node.changes)