Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native sort of objects by localeCompare vs lodash _.sortBy
(version: 0)
Comparing performance of:
native sort vs lodash sortBy
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 users = [{ 'user': 'joey', 'age': 32 }, { 'user': 'ross', 'age': 41 }, { 'user': 'chandler', 'age': 39 } ]
Tests:
native sort
users.sort((a,b) => a.user.localeCompare(b.user));
lodash sortBy
_.sortBy(users, 'user', 'asc')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
native sort
lodash sortBy
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Browser/OS:
Chrome 132 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
native sort
4142920.8 Ops/sec
lodash sortBy
2775725.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is being tested, compared, and some pros and cons of each approach. **What is being tested?** The provided benchmark compares two approaches to sorting an array of objects by a specific property: 1. **Native JavaScript sort**: The native JavaScript `sort()` function is used to sort the array. In this case, it's using the `localeCompare()` method to compare strings. 2. **Lodash _.sortBy()**: The Lodash library's `_sortBy()` function is used to sort the array. This function takes three arguments: the input array, the property to sort by, and the sorting order (in this case, "asc"). **What options are compared?** The two approaches being compared are: * **Native JavaScript sort**: uses the `localeCompare()` method to compare strings * **Lodash _.sortBy()**: takes three arguments: the input array, the property to sort by, and the sorting order (in this case, "asc") **Pros and Cons of each approach** **Native JavaScript sort:** Pros: * Fast execution time due to optimized C++ implementation under the hood * Easy to use and intuitive API Cons: * Can be slower than library-based implementations for large datasets * May not work as expected with certain edge cases (e.g., Unicode characters) **Lodash _.sortBy():** Pros: * Convenient and easy-to-use API * Supports advanced sorting features, such as stabilization and custom comparators * Well-tested and widely adopted Cons: * Slower execution time due to additional overhead from the library * May have larger memory footprint compared to native implementations **Library considerations:** In this benchmark, Lodash is used for its convenience and flexibility. The `_.sortBy()` function provides a robust way to sort arrays with various sorting options. **Special JS features or syntax:** There are no special JavaScript features or syntax being tested in this benchmark. **Other alternatives:** For large datasets, other approaches might be considered: * **Array.prototype.sort() with a custom comparator**: This approach can provide better performance and control over the sorting process. * **Other libraries like underscore.js (a faster alternative to Lodash) or Ramda**: These libraries offer similar functionality but with potentially better performance. Keep in mind that the choice of approach depends on specific use cases, project requirements, and personal preference.
Related benchmarks:
native sort of objects by localeCompare vs lodash _.sortBy
native sort of objects by localeCompare vs lodash _.orderBy swedish
native sort of objects by linus
a native sort of objects by localeCompare vs lodash _.orderBy
native sort of objects by localeCompare vs lodash _.sortBy []
Comments
Confirm delete:
Do you really want to delete benchmark?