Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash vs arr
(version: 0)
Comparing performance of:
sortBy(arr, "order_by") vs arr sort
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:
var arr = [ { "id": 3, "name": "Поездка с животным", "desc": "", "order_by": 9, "disabled": "0" }, { "id": 4, "name": "Машина без брендирования", "desc": "", "order_by": 2, "disabled": "0" }, { "id": 9, "name": "Брендированная (зелёная) машина", "desc": "", "order_by": 1, "disabled": "0" }, { "id": 12, "name": "Квитанция об оплате", "desc": "", "order_by": 6, "disabled": "0" }, { "id": 15, "name": "Проезд по КАД", "desc": "", "order_by": 11, "disabled": "0" }, { "id": 16, "name": "Проезд по КАД через Кронштадт", "desc": "", "order_by": 12, "disabled": "0" }, { "id": 17, "name": "Молчаливый водитель", "desc": "", "order_by": 10, "disabled": "0" }, { "id": 19, "name": "Деликатное вождение", "desc": "", "order_by": 7, "disabled": "0" }, { "id": 38, "name": "Данные для пропуска", "desc": "", "order_by": 36, "disabled": "0" }, { "id": 95, "name": "Помощь водителя", "desc": "", "order_by": 32, "disabled": "0" }, { "id": 98, "name": "Экспедирование", "desc": "", "order_by": 35, "disabled": "0" }, { "id": 100, "name": "Страховка груза", "desc": "", "order_by": 0, "disabled": "0" }, { "id": 101, "name": "Упаковка XS", "desc": "1 стрейч (2кг)", "order_by": 37, "disabled": "0" } ]
Tests:
sortBy(arr, "order_by")
_.sortBy(arr, "order_by");
arr sort
arr.sort((a, b) =>Number.parseInt(a.order_by) - Number.parseInt(b.order_by));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
sortBy(arr, "order_by")
arr 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):
I'll do my best to explain the benchmark and its results. **Benchmark Overview** The benchmark measures the performance of two approaches for sorting an array of objects: 1. Using Lodash's `sortBy` function with a custom compare function. 2. Implementing a simple sorting algorithm using the `Array.sort()` method. **Lodash `sortBy` Approach** In this approach, the `sortBy` function is used to sort the `arr` array based on the `order_by` property of each object. The custom compare function is used to determine the order of two objects in the sorted array. The Lodash `sortBy` function is a utility function that takes an array and a compare function as input. It returns a new sorted array based on the comparison function. In this case, the comparison function is simply returning the difference between the `order_by` values of two objects. **Array.sort() Approach** In this approach, the `Array.sort()` method is used to sort the `arr` array. The sorting algorithm used by the browser's JavaScript engine is not explicitly specified in the benchmark results. However, it is likely that the V8 JavaScript engine (used by Chrome) uses a variation of the merge sort or insertion sort algorithm. **Comparison** The two approaches have different performance characteristics: * Lodash `sortBy` approach: + Pros: More flexible and customizable sorting order. + Cons: May have overhead due to the use of a separate library. * Array.sort() approach: + Pros: Fast and lightweight, with minimal overhead. + Cons: Less flexible and customizable sorting order. **Device-Specific Optimizations** The benchmark results show that both approaches are executed at a high rate on Chrome 97 on desktop devices. However, the Lodash `sortBy` approach has slightly higher execution rates than the Array.sort() approach. It is likely that the browser's JavaScript engine has optimized the sorting algorithm for this specific use case. **Other Considerations** There are other factors to consider when evaluating the performance of these two approaches: * Memory usage: The Lodash library may have a larger memory footprint than the built-in `Array` object. * Code size: The Lodash `sortBy` function is typically larger and more complex than the simple sorting algorithm used by Array.sort(). * Compatibility: The Lodash library may not be compatible with older browsers or environments. **Alternatives** If you need to sort an array of objects, other alternatives include: * Using a different JavaScript library, such as Moment.js for date sorting. * Implementing a custom sorting algorithm using a language like C++ or Rust. * Using a specialized sorting library, such as QuickSort or Merge Sort.
Related benchmarks:
lodash vs es6 in find method
lodash vs es6 in filter method
lodash vs es6 in some method
lodash vs es6 in every method
String vs Object find
Comments
Confirm delete:
Do you really want to delete benchmark?