lodash vs ES6 sortby
Date tested:
3 months ago
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Test name
Executions per second
lodash orderby
1022617.0 Ops/sec
native sort
1919475.0 Ops/sec
Benchmark definition (click to collapse):
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var fruits = [ {name:"banana", amount: 2}, {name:"apple", amount: 4}, {name:"pineapple", amount: 2}, {name:"mango", amount: 1} ]; sortBy = (key) => { return (a, b) => (a[key] > b[key]) ? 1 : ((b[key] > a[key]) ? -1 : 0); };
Tests:
lodash orderby
_.orderBy(fruits, ['name'],['asc']);
native sort
fruits.concat().sort(sortBy("name"));
Open this result on MeasureThat.net