Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash partition vs ES6
(version: 0)
Comparison of using lodash partition against raw ES6
Comparing performance of:
_.partition vs ES6 partition
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 = [ { name: 'john', hasPet: true }, { name: 'jack', hasPet: false }, { name: 'jill', hasPet: false }, { name: 'james', hasPet: true }, { name: 'jane', hasPet: false }, ]
Tests:
_.partition
_.partition(arr);
ES6 partition
const partition = (arr) => { return [ ...arr.filter(el => el.hasPet), ...arr.filter(el => !el.hasPet) ] }; partition(arr);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.partition
ES6 partition
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/128.0.0.0 Safari/537.36
Browser/OS:
Chrome 128 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.partition
7706606.5 Ops/sec
ES6 partition
10632849.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Explanation** MeasureThat.net provides a comparison of two approaches to partitioning an array: Lodash's `partition` function and the raw ES6 implementation. **Lodash Partition** The `partition` function from Lodash is a utility function that takes an array and returns two separate arrays, one for elements that pass a test (true) and another for elements that fail the test. The original array remains unchanged. In this benchmark, the `partition` function is used to split the provided array into two parts: one with objects that have a `hasPet` property set to `true`, and another with objects that do not have a `hasPet` property set. **ES6 Partition** The raw ES6 implementation is a simple function that takes an array and returns two separate arrays using the spread operator (`...`). It filters the original array into two parts: one for elements that pass the test (i.e., `el.hasPet` is truthy) and another for elements that fail the test (i.e., `el.hasPet` is falsy). **Comparison** The main difference between the two approaches is the complexity of the implementation: * Lodash's `partition` function is a pre-built utility function that encapsulates the logic, making it easy to use and maintain. * The raw ES6 implementation is a simple, hand-rolled function that requires more boilerplate code. **Pros and Cons** **Lodash Partition:** Pros: * Simplifies the implementation by providing a reusable utility function * Less boilerplate code Cons: * Requires an external library (Lodash) to be included in the test environment * May have overhead due to the inclusion of the library **ES6 Partition:** Pros: * No external dependencies required * Can be optimized for specific use cases Cons: * More complex implementation requiring more boilerplate code * May not be as easy to maintain or reuse **Other Considerations** When choosing between these two approaches, consider the trade-offs between simplicity, reusability, and performance. If you prioritize ease of use and don't mind including an external library, Lodash's `partition` function may be a good choice. However, if you prefer a more lightweight implementation or want to optimize for specific use cases, the raw ES6 partition implementation might be a better fit. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for common tasks, such as array manipulation, object iteration, and function creation. The `partition` function is just one example of the many useful utilities available in Lodash. In this benchmark, including the Lodash library allows users to easily test the `partition` function without having to implement it from scratch. However, if you don't need the full range of Lodash functions, you can simply remove or comment out the script tag that includes the library. **Special JS Feature: None** There are no special JavaScript features or syntax used in this benchmark beyond standard ES6 functionality.
Related benchmarks:
Lodash partition VS native reduce
Lodash some vs Native some
Lodash partition vs ES6 for..of partition
Lodash partition VS native reduce (with Lodash actually loaded)
Comments
Confirm delete:
Do you really want to delete benchmark?