Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash sortBy vs orderBy2
(version: 0)
Lodash sortBy vs orderBy
Comparing performance of:
_.sortBy vs _.orderBy
Created:
4 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:
function getRandomInt(max) { return Math.floor(Math.random() * Math.floor(max)); } var arr = []; for(var i = 0; i < 100000; i++){ arr.push({value:getRandomInt(100)}); }
Tests:
_.sortBy
_.sortBy(arr,"value");
_.orderBy
_.orderBy(arr,"value");
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.sortBy
_.orderBy
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 the provided benchmark definition and test cases. **Benchmark Definition JSON:** The benchmark definition is a JSON object that contains information about the benchmark being tested. The key points are: * "Name": A human-readable name for the benchmark, which in this case is "Lodash sortBy vs orderBy". * "Description": A brief description of the benchmark, which in this case highlights the comparison between two Lodash functions: `sortBy` and `orderBy`. * "Script Preparation Code": This section contains code that is executed before running the benchmark. In this case, it creates an array `arr` with 100,000 objects, each containing a random integer value. * "Html Preparation Code": This section includes a script tag that loads the Lodash library (version 4.17.5) from a CDN. **Individual Test Cases:** The benchmark consists of two test cases: 1. `_.sortBy(arr, "value");`: This test case runs the `sortBy` function on the prepared array `arr`, sorting it in ascending order based on the values. 2. `_.orderBy(arr, "value");`: This test case runs the `orderBy` function on the prepared array `arr`, also sorting it in ascending order based on the values. **What's being tested:** The benchmark is testing the performance of two Lodash functions: * `sortBy`: Sorts an array in a specific order (ascending, in this case). * `orderBy`: Similar to `sortBy`, but with a different internal implementation. **Options compared:** * **Lodash's internal sorting algorithm**: The benchmark compares the execution times of two different algorithms used by Lodash to sort arrays: `sortBy` and `orderBy`. * **Array data structure**: Although not explicitly stated, it is likely that the benchmark assumes an array data structure for the input. **Pros and Cons of the compared options:** * `sortBy`: + Pros: May be more flexible or customizable, as it can sort in multiple directions (ascending/descending). + Cons: Might have a higher overhead due to its internal implementation. * `orderBy`: + Pros: Could potentially be faster or more efficient, especially for large arrays. + Cons: Its specific internal implementation might not be suitable for all use cases. **Library and syntax usage:** The test case uses the Lodash library (version 4.17.5). The `_` notation is used as a prefix to access functions within the library. **Special JS feature or syntax:** There are no special JavaScript features or syntaxes explicitly mentioned in the benchmark definition or individual test cases. **Alternatives:** Other alternatives for sorting arrays could include: * Using the built-in `sort()` method of the Array prototype. * Implementing a custom sorting algorithm using a data structure like a heap or a balanced binary search tree. * Utilizing a third-party library with optimized sorting algorithms, such as MoJS or SortJS. Keep in mind that this is just a brief explanation, and there may be additional nuances or complexities to the benchmark not covered here.
Related benchmarks:
Lodash orderBy vs array.prototype.sort
Lodash orderBy() vs array.prototype.sort
Lodash sortBy vs orderBy performance
Lodash orderBy vs array.prototype.sort fork
Lodash orderBy (fn) vs array.prototype.sort small array
Comments
Confirm delete:
Do you really want to delete benchmark?