Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Comparing _orderBy with native sort
(version: 0)
Comparing performance of:
_.orderBy vs array.prototype.sort
Created:
7 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.10/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'], ['asc']);
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 dive into the explanation of what's tested in this benchmark. **Benchmark Definition** The benchmark is designed to compare two approaches for sorting an array: using the `_orderBy` function from Lodash and native JavaScript `sort()` method. **Options Compared** Two options are compared: 1. **Lodash `_orderBy`**: This function takes an array (`arr`) and returns a new sorted array based on a specified property (`'value'`). The sort order can be either ascending (`'asc'`) or descending. 2. **Native JavaScript `sort()` method**: This is a built-in method in JavaScript that sorts the elements of an array in place, returning the array itself. **Pros and Cons** Here are some pros and cons of each approach: * Lodash `_orderBy`: + Pros: Easy to use, concise syntax, efficient implementation. + Cons: Requires the use of a third-party library (Lodash), may not be familiar to all developers. * Native JavaScript `sort()` method: + Pros: Built-in and widely supported, no additional dependencies required. + Cons: More verbose syntax, less intuitive than `_orderBy`, may have performance issues if not implemented correctly. **Library** The Lodash library is a popular utility belt for functional programming in JavaScript. It provides a wide range of functions for various tasks, including sorting arrays. In this benchmark, the `_.orderBy` function is used to sort the array based on the `'value'` property. **Special JS feature or syntax** There doesn't appear to be any special JavaScript features or syntax being used in this benchmark. However, it's worth noting that the use of Lodash requires importing a third-party library, which may not be familiar to all developers. **Other alternatives** If you wanted to implement an alternative sorting algorithm for this benchmark, some options could include: * Using a custom implementation of quicksort or mergesort. * Employing a more advanced data structure like a heap or balanced binary search tree. * Utilizing a library like `underscore` (not Lodash) or another utility belt with similar functionality. Keep in mind that these alternatives would require significant changes to the benchmark code and may not provide comparable results.
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
Comments
Confirm delete:
Do you really want to delete benchmark?