Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Array.sort vs Array.map
Sort array according to sort order of other array
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Array.sort + Array.findIndex
223.1 Ops/sec
Array.map + Array.find
302.8 Ops/sec
Script Preparation code:
const shuffleArray = array => { const arr = [...array]; for (let i = arr.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); const temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } return arr; } var testArr = Array.from({ length: 5000 }, () => Math.floor(Math.random() * 4000)); var scrambled = shuffleArray(testArr);
Tests:
Array.sort + Array.findIndex
scrambled.sort((a,b) => testArr.findIndex(t => t === a) - testArr.findIndex(t => t === b));
Array.map + Array.find
testArr.map((t) => scrambled.find(s => s === t));