Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash sortBy vs Lodash orderBy
(version: 0)
Lodash sortBy vs Lodash orderBy
Comparing performance of:
_.sortBy vs _.orderBy
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:
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 benchmark and explain what's being tested. **Benchmark Overview** The benchmark is comparing two versions of Lodash functions: `sortBy` and `orderBy`. The test case creates an array of 100,000 objects with random values between 0 and 100. The purpose of this setup is to allow for a large-scale comparison of the performance of these two sorting functions. **Options being compared** The options being compared are: 1. `_.sortBy(arr, "value")` 2. `_.orderBy(arr, "value")` Both functions take an array (`arr`) and a sort key (`"value"`). The main difference between them is how they handle the sorting: * `_.sortBy` returns a new sorted array without modifying the original array. * `_.orderBy` modifies the original array by sorting it in place. **Pros and Cons of each approach** 1. **_.sortBy** * Pros: + Does not modify the original array, preserving its integrity. + Allows for more flexibility when working with complex data structures. * Cons: + Creates a new sorted array, which can lead to increased memory usage. 2. **_.orderBy** * Pros: + Modifies the original array in place, reducing memory usage. * Cons: + Modifies the original array, potentially affecting other parts of the code. **Library and its purpose** The Lodash library is a popular JavaScript utility library that provides a wide range of functions for various tasks, including string manipulation, array manipulation, and more. The `sortBy` and `orderBy` functions are part of the Lodash `MoreUtils` module, which provides additional utilities for working with arrays. **Special JS feature or syntax** There doesn't appear to be any special JavaScript features or syntax being tested in this benchmark. The test case only uses standard JavaScript syntax and libraries. **Other alternatives** If you were to implement a custom sorting algorithm instead of using Lodash's `sortBy` and `orderBy` functions, some alternatives could include: * Using the built-in `Array.prototype.sort()` method. * Implementing a quicksort or mergesort algorithm from scratch. * Using a library like Fast Sort or Dual-Pivot Quicksort. However, these alternatives would likely have different performance characteristics and trade-offs compared to Lodash's optimized implementations.
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?