Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
sort object
(version: 0)
Comparing performance of:
lodash vs arr
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.5/lodash.min.js'></script>
Script Preparation code:
var param = { "date": "2019/02/11", "time": "08:00:00", "ex": true }; var fruits = [ { "date": "2019/02/01", "time": "08:00:00", "ex": true }, { "date": "2019/02/08", "time": "06:00:00", "ex": false }, { "date": "2019/02/06", "time": "07:30:00", "ex": false }, { "date": "2019/02/14", "time": "10:00:00", "ex": true }, { "date": "2019/02/11", "time": "05:45:00", "ex": true } ];
Tests:
lodash
fruits.sort(function(a,b){ return a.time > b.time; });
arr
_.sortBy(fruits, "time");
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash
arr
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash
5328431.5 Ops/sec
arr
1093840.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in the provided JSON and explain the options, pros, and cons of each approach. **Benchmark Definition** The benchmark is testing the sorting of an object array using two different methods: 1. `fruits.sort(function(a,b){ return a.time > b.time; });` 2. `_.sortBy(fruits, "time");` **Options compared:** We have two options to sort the array: a. **JavaScript Array.prototype.sort() method**: This is a built-in method that sorts the elements of an array in place, returning the sorted array. The sorting algorithm used by this method is typically Timsort, which is a hybrid sorting algorithm derived from merge sort and insertion sort. b. **Lodash's _.sortBy() function**: This is a utility function provided by the Lodash library, which sorts the elements of an array based on a given attribute or key. **Pros and Cons:** a. **JavaScript Array.prototype.sort() method**: Pros: * Fast and efficient for small to medium-sized arrays * Built-in method, so no additional library is required Cons: * Can be slow for very large arrays (due to its Timsort algorithm) * May not perform well if the array contains duplicate values or complex data structures b. **Lodash's _.sortBy() function**: Pros: * More efficient and faster than JavaScript Array.prototype.sort() method, especially for larger arrays * Can handle complex data structures and duplicate values without issues * Part of a larger utility library that provides other useful functions Cons: * Requires an additional library (Lodash) to be included in the project * May have a slightly higher overhead due to the additional library **Library used:** In this benchmark, Lodash is being used as part of the "arr" test case. The `_.sortBy()` function is a key part of Lodash's utility suite, providing a convenient way to sort arrays based on various attributes or keys. **Special JS feature/syntax:** There are no special JavaScript features or syntaxes being tested in this benchmark. The code is straightforward and uses standard JavaScript array methods. **Other alternatives:** If you wanted to test other sorting algorithms or techniques, some alternatives could include: * Using the `Array.prototype.sort()` method with a custom comparison function * Implementing your own sorting algorithm (e.g., quicksort, mergesort) * Using a different library or framework that provides its own sorting utilities However, it's worth noting that JavaScript Array.prototype.sort() is generally considered a good default choice for most use cases, so unless you have specific requirements or constraints, this would likely be the preferred option.
Related benchmarks:
_.sortBy vs native sort
lodash vs es6 in sort method
lodash vs ES6 sortby
lodash vs ES6 sortby native fix
Comments
Confirm delete:
Do you really want to delete benchmark?