Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash vs ES6 sortby native
(version: 0)
Comparing performance of:
lodash orderby vs native sort
Created:
3 years ago
by:
Guest
Jump to the latest result
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, ['amount'],['asc']);
native sort
fruits.sort((first, second) => first - second);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash orderby
native sort
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's happening in this benchmark. **What is being tested?** The main difference between the two test cases is how sorting is implemented: using Lodash (`_`) vs native JavaScript. In both cases, we have an array of objects `fruits` with a property `amount`. The goal is to sort these objects by `amount`. **Options compared** We have two approaches: 1. **Lodash (`_`).orderBy**: Lodash provides a utility function `orderBy` that sorts an array of objects based on a specified key (in this case, `'amount'`) in either ascending or descending order. 2. **Native JavaScript `.sort()`**: The native JavaScript method for sorting arrays uses a comparison function to determine the order of elements. **Pros and Cons** * Lodash: + Pros: Convenient utility function, easy to use, and well-maintained. + Cons: Adds additional dependency (Lodash), might be slower due to overhead. * Native JavaScript `.sort()`: + Pros: Fast, lightweight, and native implementation. + Cons: Requires implementing a comparison function, can be more error-prone. **Library usage** In the benchmark definition, we're using Lodash. Specifically, it's being used for its `orderBy` utility function. The library is included via a CDN link (`https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js`). **Special JavaScript features or syntax** There are no special JavaScript features or syntax mentioned in this benchmark. However, it's worth noting that the comparison function used with `sort()` (in both cases) relies on a common pattern: `(a[key] > b[key]) ? 1 : ((b[key] > a[key]) ? -1 : 0)`. This is a standard approach for sorting arrays. **Other alternatives** If you wanted to implement sorting using Lodash but didn't want to use the `orderBy` function, you could also use other methods like `_map`, `_sort`, or create your own custom sorting function. For native JavaScript, you could explore alternative sorting algorithms like quicksort or mergesort, although these might be overkill for simple cases. In summary, this benchmark compares the performance of using Lodash's `orderBy` function versus implementing a native JavaScript `.sort()` method.
Related benchmarks:
sortby vs orderby
sortBy performance1
lodash vs ES6 sortby
lodash vs ES6 sortby native fix
Comments
Confirm delete:
Do you really want to delete benchmark?