Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Reduce + findIndex vs Loops + Object.values()
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15
Browser:
Safari 17
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
reduce + findIndex
1187.7 Ops/sec
Loops + Object.keys
3139.2 Ops/sec
Tests:
reduce + findIndex
const movies = Array.from({ length: 50 }).map(() => ({ characters: Array.from({ length: 50 }).map((_, i) => ({ id: Math.floor(Math.random() * 100), })), })); const mergedCharacters = movies.reduce( (characters, movie) => characters.concat(movie.characters), [] ); const uniqueCharacters = mergedCharacters.filter( (character, index) => mergedCharacters.findIndex((mCharacter) => mCharacter.id === character.id) === index );
Loops + Object.keys
const movies = Array.from({ length: 50 }).map(() => ({ characters: Array.from({ length: 50 }).map((_, i) => ({ id: Math.floor(Math.random() * 100) })) })) const uniqueCharacters = {} for (let i = 0; i < movies.length; i++) { for (let j = 0; j < movies[i].characters.length; j++) { uniqueCharacters[movies[i].characters[j].id] = movies[i].characters[j]; } } const characters = Object.values(uniqueCharacters);