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 native sort of objects by localeCompare vs lodash _.sortBy
Comparing performance of:
native sort of objects by localeCompare vs lodash _.orderBy
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.core.js"></script>
Script Preparation code:
var users = [ { 'user': '[joey]', 'age': 32 }, { 'user': 'ross', 'age': 41 }, { 'user': 'chandler', 'age': 39 } ]
Tests:
native sort of objects by localeCompare
users.sort((a,b) => a.user.localeCompare(b.user));
lodash _.orderBy
_.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 of objects by localeCompare
lodash _.orderBy
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser/OS:
Chrome 121 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
native sort of objects by localeCompare
9818206.0 Ops/sec
lodash _.orderBy
3383276.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and test cases. **What is being tested?** The primary goal of this benchmark is to compare the performance of two sorting methods: 1. Native JavaScript sort using the `localeCompare` method. 2. Lodash _.sortBy function, which is a higher-order function that sorts an array based on a specific key. These two approaches are compared in terms of their execution speed and stability. **Options compared:** The benchmark compares the native JavaScript sort with the Lodash _.sortBy function. The options being compared include: * Native JavaScript sort using `localeCompare` method. * Lodash _.sortBy function, which sorts an array based on a specific key. **Pros and Cons of each approach:** 1. **Native JavaScript sort using localeCompare:** * Pros: + Built-in functionality, no additional library required. + Can handle non-ASCII characters correctly. * Cons: + May not be as efficient as other sorting algorithms like quicksort or mergesort. + Can be sensitive to the order of operations and locale settings. 2. **Lodash _.sortBy function:** * Pros: + More efficient than native JavaScript sort for large datasets. + Provides more flexibility in terms of sorting options (e.g., ascending/descending, stable sorting). * Cons: + Requires an additional library (Lodash) to be included. + May not perform as well on very small datasets. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for various tasks, including array manipulation, string manipulation, and more. In this benchmark, the Lodash _.sortBy function is used to sort an array based on a specific key. **Special JS feature or syntax: None mentioned in the benchmark definition** However, it's worth noting that JavaScript has some advanced features like async/await, Promises, and Web Workers that are not present in this benchmark. **Other alternatives:** If you need to sort arrays in JavaScript, other alternatives include: * **Array.prototype.sort()**: This is a built-in method for sorting arrays using the default sorting order (ascending). * **Quicksort**: A popular sorting algorithm that has an average time complexity of O(n log n) but can be slower than mergesort or heapsort. * **Mergesort**: Another efficient sorting algorithm with an average time complexity of O(n log n). * **Heap sort**: A comparison-based sorting algorithm with a time complexity of O(n log n). It's worth noting that the choice of sorting algorithm depends on the specific requirements and constraints of your application.
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
Comments
Confirm delete:
Do you really want to delete benchmark?