Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash sortBy vs orderBy_fork
(version: 0)
Lodash sortBy vs orderBy
Comparing performance of:
_.sortBy vs _.orderBy vs ES6
Created:
2 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");
ES6
arr.sort((a, b) => a - b)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
_.sortBy
_.orderBy
ES6
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 what's being tested in this benchmark. **Benchmark Definition JSON** The test case uses Lodash, a popular JavaScript library for functional programming utilities. The three benchmark definitions are: 1. `_.sortBy(arr,"value")`: This tests the `sortBy` function from Lodash, which sorts an array by a specified attribute. 2. `_.orderBy(arr,"value")`: This tests the `orderBy` function from Lodash, which also sorts an array by a specified attribute, but with some differences in implementation compared to `sortBy`. 3. `arr.sort((a, b) => a - b)`: This is a native JavaScript implementation of the sort method using a compare function. **Options Compared** The benchmark compares the performance of: * Lodash's `sortBy` and `orderBy` functions * Native JavaScript's `sort` method These two approaches have different design principles and implementation details, which affect their performance characteristics. **Pros and Cons of Each Approach** 1. **Lodash (`sortBy` and `orderBy`)**: * Pros: + Higher-level abstraction: Lodash abstracts away many low-level details, making it easier to write clean code. + Faster development: With a pre-written implementation, developers can focus on other aspects of their codebase. + Robustness: Lodash's implementation often includes optimizations and edge cases that might not be immediately apparent when implementing from scratch. * Cons: + Overhead: Using a library like Lodash introduces additional overhead due to the need for function calls, checks, and potentially slower performance compared to native implementations. 2. **Native JavaScript (`arr.sort((a, b) => a - b)`)**: * Pros: + Performance: Native code is often optimized for performance, with fewer overheads than external libraries. + Control: By writing the implementation yourself, you have complete control over every detail. * Cons: + Lower-level complexity: Implementing sorting algorithms requires a deeper understanding of data structures and algorithms. **Library (Lodash) and its Purpose** Lodash is a utility library for functional programming in JavaScript. It provides a wide range of functions that make it easier to work with arrays, objects, and other data structures. The `sortBy` and `orderBy` functions are part of this collection, providing a convenient way to sort arrays. **Special JS Feature or Syntax** There is no special JavaScript feature or syntax used in this benchmark beyond what's typically available in modern browsers (ECMAScript 2015+). **Other Alternatives** For those interested in alternative sorting algorithms or libraries, here are some options: * **Native sort methods**: Besides the built-in `sort` method, you can also use `Array.prototype.every`, `Array.prototype.some`, and other array methods to implement custom sorting logic. * **External sorting libraries**: Libraries like [fast-sort](https://github.com/isaacs/fast-sort) or [d3-array-queue](https://github.com/mbostock/d3-array-queue) offer optimized sorting algorithms for specific use cases. * **Specialized sorting libraries**: Libraries like [underscore](https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.13.1/underscore.min.js) (similar to Lodash) or [ramda](https://github.com/ramdajs/ramda) provide various sorting functions with different focus areas. Keep in mind that the choice of library, implementation, or algorithm ultimately depends on your specific requirements, performance constraints, and personal preferences.
Related benchmarks:
Lodash orderBy() vs array.prototype.sort
lodash sortBy vs native sortBy 4.17.21
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?