Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Date sort
(version: 0)
Comparing performance of:
native sort vs lodash 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:
var arr = []; for(var i = 0; i < 1000; i++){ arr.push({updatedAt: new Date(+(new Date()) - Math.floor(Math.random()*10000000000))}); }
Tests:
native sort
arr.sort((a,b) => { a = new Date(a.dateModified); b = new Date(b.dateModified); return a>b ? -1 : a<b ? 1 : 0; })
lodash sort
_.sortBy(arr,"updatedAt", "desc");
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
native sort
lodash sort
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
native sort
4897.6 Ops/sec
lodash sort
572.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark definition and test cases to understand what's being tested. **Benchmark Definition Json** The provided JSON defines two benchmarks: 1. **Date Sort**: This is the name of the benchmark, but it doesn't have a description. The script preparation code generates an array of 1000 objects with `updatedAt` properties set to random dates in the past. 2. **Benchmark Definition**: This is the actual benchmark code. There are two test cases: * **Native Sort**: This uses the built-in `sort()` method on the array, sorting it by date in descending order. * **Lodash Sort**: This uses the `_sortBy()` function from the Lodash library to sort the array by date in descending order. **Options Compared** The two test cases compare the performance of: 1. Built-in JavaScript `sort()` method 2. External library (Lodash) implementation for sorting **Pros and Cons** * **Built-in JavaScript `sort()` method**: + Pros: Fast, widely supported, and easy to use. + Cons: May not be as efficient as external implementations for large datasets or specific use cases. * **Lodash `sortBy()` function**: + Pros: Can be more efficient than the built-in `sort()` method for certain data structures or sorting algorithms. Lodash is a well-tested and maintained library with a wide range of features. + Cons: Adds overhead due to external library dependencies, which may affect performance. **Lodash Library** The Lodash library provides a set of utility functions for functional programming, including `sortBy()`, which sorts an array by a specified property in either ascending or descending order. In this case, we're using it to sort the array by date in descending order (`"desc"`). **Other Considerations** When writing benchmarks like these, it's essential to consider factors such as: * Data size and distribution * Sorting algorithm used (e.g., quicksort, mergesort) * Implementation details (e.g., caching, memoization) **Alternatives** If you're interested in exploring alternative sorting algorithms or libraries, some options include: 1. **External sorting libraries**: Libraries like QuickSort or Merge Sort can be implemented and tested for performance. 2. **Native JavaScript sorting algorithms**: Alternative sorting algorithms like radix sort or integer sorting can be used instead of the built-in `sort()` method. 3. **Other Lodash functions**: Depending on your use case, other Lodash functions like `_map()`, `_reduce()`, or `_filter()` might be more suitable for benchmarking. Keep in mind that each alternative may introduce new variables to consider when writing benchmarks, such as implementation overhead, memory usage, and edge cases.
Related benchmarks:
Lodash sort vs array.prototype.sort datestring
Lodash min vs sort moment (lodash 4.7.11)
Lodash orderBy vs Array.prototype.sort for dates
Lodash SortBy Vs Stable Sort
Comments
Confirm delete:
Do you really want to delete benchmark?