Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash orderby vs sort
(version: 0)
Comparing performance of:
_.orderBy vs array.prototype.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.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:
_.orderBy
_.orderBy(arr, ["value"]);
array.prototype.sort
arr.sort((a,b) => a.value - b.value);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.orderBy
array.prototype.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 break down the provided benchmarking test case. **What is tested?** The benchmark tests two approaches to sort an array of objects in ascending order: 1. `_.orderBy(arr, ["value"])`: This uses the Lodash library's `orderBy` function, which sorts an array based on a specified property. 2. `arr.sort((a,b) => a.value - b.value)`: This is the built-in JavaScript `sort()` method, which sorts an array in place by comparing elements using a provided comparison function. **Options compared** The two options are compared in terms of their performance (measured in executions per second). **Pros and Cons of each approach:** 1. **Lodash's `_orderBy` function** * Pros: + Provides a more readable and maintainable way to sort arrays, as it abstracts away the underlying implementation details. + Can handle complex sorting scenarios with multiple properties. * Cons: + Adds an external library dependency, which may incur additional overhead. + May have slower performance due to the overhead of the library's internal workings. 2. **Built-in JavaScript `sort()` method** * Pros: + No external library dependencies, resulting in potentially faster execution times. + Native implementation, optimized for performance. * Cons: + Requires a more verbose and less readable comparison function. + May not be suitable for complex sorting scenarios. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, string manipulation, and functional programming. The `_orderBy` function is part of the Lodash library's "Utility Functions" collection, which provides various ways to manipulate arrays, including sorting. **Special JS feature or syntax: None** Neither of the tested approaches uses any special JavaScript features or syntax that would require additional explanation. **Other alternatives:** If you want to avoid using an external library like Lodash, you could consider implementing your own sorting algorithm from scratch. Alternatively, you could explore other libraries like Moment.js (for date-based sorting) or a custom sorting library specifically designed for JavaScript. For the built-in `sort()` method, if you need more advanced sorting capabilities, you might want to consider using a library like [lodash.sortby](https://github.com/lodash/lodash-sortby) or implementing your own custom sorting algorithm.
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?