Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
lodash orderBy vs Array.sort
Sort and array of objects by 2 properties : - text: descending - id: ascending
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/134.0.0.0 Safari/537.36 Edg/134.0.0.0
Browser:
Chrome 134
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Array.sort
379K/s
_.orderBy
26K/s
View exact numbers
Test name
Executions per second
✓
Array.sort
379,145 Ops/sec
_.orderBy
25,856 Ops/sec
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var generateText = function(){ return Math.random().toString(36).substring(2, 4); } var arr = [] for(i=0; i<100; i++){ const obj = {} obj.id = i; obj.text = generateText() arr.push(obj) }
Tests:
_.orderBy
_.orderBy(arr, ['text', 'id'], ['desc', 'asc'])
Array.sort
arr.sort((a, b) => (a.text < b.text) ? 1 : (a.text === b.text) ? ((a.id > b.id) ? 1 : -1) : -1 )