Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash vs native sort
(version: 0)
Comparing performance of:
lodash sortBy vs native sort
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js'></script>
Script Preparation code:
var test = [ { ETag: "\"70ee1738b6b21e2c8a43f3a5ab0eee71\"", Key: "happyface.jpg", LastModified: 'Apr 22, 2020 12:48:21 AM GMT-0400', Size: 11, StorageClass: "STANDARD" }, { ETag: "\"becf17f89c30367a9a44495d62ed521a-1\"", Key: "test.jpg", LastModified: 'Apr 23, 2020 12:48:21 AM GMT-0400', Size: 4192256, StorageClass: "STANDARD" }, { ETag: "\"becf17f89c30367a9a44495d62ed521a-2\"", Key: "test2.jpg", LastModified: 'Apr 18, 2020 12:48:21 AM GMT-0400', Size: 4192256, StorageClass: "STANDARD" } ]
Tests:
lodash sortBy
_.sortBy(test, [function(o) { return o.LastModified }])
native sort
test.sort(function (a, b) { return a.LastModified - b.LastModified })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash sortBy
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 dive into the explanation of the benchmark. **Benchmark Definition JSON** The provided JSON represents a JavaScript microbenchmark, which measures the performance of two different approaches for sorting an array of objects: native sort and Lodash's `sortBy` function. **What is tested?** Two test cases are defined: 1. **Lodash sortBy**: This test case uses the Lodash library to sort the `test` array based on the `LastModified` property of each object. The `sortBy` function takes two arguments: the array to be sorted (`test`) and a callback function that defines the sorting criteria (`function(o) { return o.LastModified }`). 2. **Native sort**: This test case sorts the same `test` array using JavaScript's built-in `sort` method, which also takes a callback function as an argument to define the sorting criteria. **Options compared** The two approaches are compared in terms of their performance: * **Lodash sortBy**: Uses the Lodash library to perform the sort. * **Native sort**: Uses JavaScript's built-in `sort` method without any external libraries. **Pros and Cons** Here are some pros and cons of each approach: * **Lodash sortBy**: + Pros: - Easy to use: Simply include the Lodash library in your HTML file or load it via a CDN. - Well-tested and optimized for performance. + Cons: - Requires an external library, which may increase page load time. - May not be suitable for very large datasets due to memory constraints. * **Native sort**: + Pros: - No external dependencies: Only uses JavaScript's built-in `sort` method. - Suitable for large datasets. + Cons: - Requires more manual effort to implement the sorting criteria. - May be slower than Lodash's implementation due to its native nature. **Library usage** The Lodash library is used in this benchmark. Lodash is a popular utility library that provides a wide range of functions for tasks such as string manipulation, array manipulation, and more. In this case, the `sortBy` function is used to sort the array based on a custom criteria. **Special JS features or syntax** No special JavaScript features or syntax are used in this benchmark. The code uses standard JavaScript syntax and built-in methods like `sort`, `forEach`, and `array.prototype.push`. **Other alternatives** If you prefer not to use an external library, you can also implement the sorting logic using only native JavaScript functions. For example: ```javascript function sortByNative(arr) { return arr.sort((a, b) => a.LastModified - b.LastModified); } ``` This approach would be suitable for small datasets, but may become slower and less efficient as the dataset grows. Keep in mind that this benchmark is designed to measure performance, so the choice of approach ultimately depends on your specific use case and requirements.
Related benchmarks:
_.sortBy vs native sort
compare _.SortBy vs Sort
compare _.SortBy vs Sort 1234
lodash vs es6 in sort method
order desc with lodash orderBy vs es6 sort method
Comments
Confirm delete:
Do you really want to delete benchmark?