Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash partition VS native reduce (with Lodash actually loaded)
(version: 0)
Comparing performance of:
Lodash vs Native reduce
Created:
one year 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 (i = 0; i < 1000; i++) { arr[i] = i; } _.partition([], function() { return false });
Tests:
Lodash
var [met, rest] = _.partition(arr, function(i) { return i % 2 === 0 });
Native reduce
var [met, rest] = arr.reduce(function([p1, p2], i) { return i % 2 === 0 ? [[...p1, i], p2] : [p1, [...p2, i]] }, [[], []])
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash
Native reduce
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Browser/OS:
Chrome 127 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
282647.9 Ops/sec
Native reduce
4897.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is being tested. **Benchmark Overview** The benchmark compares two approaches to partitioning an array: using Lodash's `partition` function versus implementing a native reduction method. The test creates an array of 1000 elements, where each element is a unique integer, and then attempts to partition the array into two parts based on whether the element is even or odd. **Options Compared** The benchmark tests two options: 1. **Lodash's `partition` function**: This approach uses Lodash's built-in `partition` function to split the array into two parts. 2. **Native reduction method**: This approach uses a custom implementation of a reduction method to achieve the same partitioning result. **Pros and Cons** Here are some pros and cons for each approach: * **Lodash's `partition` function**: + Pros: Easy to use, efficient, and well-tested. + Cons: Requires loading an additional library (Lodash), which may introduce overhead. * **Native reduction method**: + Pros: Faster execution times since no external library is required, and the code can be optimized for specific use cases. + Cons: More complex to implement, requires manual handling of array partitioning logic. **Library Usage** In this benchmark, Lodash is used in two ways: * **Script Preparation Code**: Lodash's `lodash.min.js` library is loaded via a script tag, which allows the user to easily include the library in their environment. * **Benchmark Definition**: The `partition` function is called using the `_` alias (i.e., `_.partition(arr, ...)`) to access the `partition` method from Lodash. **Special JS Feature/Syntax** None of the benchmark's code uses any special JavaScript features or syntax that requires explanation. Both approaches rely on standard JavaScript array methods and operators. **Other Alternatives** If you're interested in exploring alternative partitioning methods, here are a few options: * **Array.prototype.filter()**: You can use `filter()` to create two arrays based on the condition: one for elements that pass the test and another for those that don't. * **Array.prototype.map() + Array.prototype.slice()**: You can use `map()` to transform the array into two smaller arrays, one for even numbers and one for odd numbers, using `slice()` to separate them. In summary, the benchmark provides a simple yet informative comparison between two approaches to partitioning an array: Lodash's `partition` function versus a native reduction method.
Related benchmarks:
Lodash reduce with native reduce
Lodash partition VS native reduce
Lodash reduce vs native
lodash partition vs reduce with array push vs two filter loops
Comments
Confirm delete:
Do you really want to delete benchmark?