Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Array sort & map vs. map & sort
The best way to map and sort array of arrays
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser:
Chrome 121
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
map & sort
51.6 Ops/sec
sort & map
137.7 Ops/sec
Script Preparation code:
function getRandomInt(max) { return Math.floor(Math.random() * Math.floor(max)); } var arr = []; for(var i = 0; i < 100000; i++){ arr.push([-1,getRandomInt(100)]); }
Tests:
map & sort
arr.map(r => r[1]).sort()
sort & map
arr.sort((a,b) => a[1]-b[1]).map(r => r[1])