Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash chunk vs native
(version: 0)
Comparing performance of:
Lodash chunk vs Native Chunk
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 test = Array.from({ length: 100000 }, () => Math.random())
Tests:
Lodash chunk
_.chunk(test,5000)
Native Chunk
const chunk = (input, size) => { return input.reduce((arr, item, idx) => { return idx % size === 0 ? [...arr, [item]] : [...arr.slice(0, -1), [...arr.slice(-1)[0], item]]; }, []); }; chunk(test,5000)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash chunk
Native Chunk
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/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash chunk
8176.3 Ops/sec
Native Chunk
5.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what is being tested, compared, and discussed in this JavaScript microbenchmark. **What is being tested?** The benchmark tests two approaches to chunking an array of 100,000 random numbers into smaller chunks of size 5,000. There are two test cases: 1. **Lodash Chunk**: The first test case uses the `_.chunk` function from the Lodash library, a popular utility library for JavaScript. 2. **Native Chunk**: The second test case implements a custom chunking function using native JavaScript. **Options compared** The benchmark compares the performance of these two approaches: 1. **Lodash Chunk**: Uses the `_.chunk` function from the Lodash library, which is a built-in utility that performs an array transformation and returns an array of chunks. 2. **Native Chunk**: Implements a custom chunking function using native JavaScript, without relying on any external libraries. **Pros and Cons** Here's a brief analysis of each approach: * **Lodash Chunk**: + Pros: Easy to use, well-maintained library with good performance. + Cons: Requires an additional library download, might not be optimized for your specific use case. * **Native Chunk**: + Pros: No external dependencies, potentially optimized for your specific use case. + Cons: More complex implementation, requires manual optimization. **Library usage** The Lodash library is used in the first test case. Lodash provides a wide range of utility functions, including array transformations like `_.chunk`. This library can improve code readability and maintainability but may introduce additional overhead due to the download and execution time. **Special JS features or syntax** There are no special JavaScript features or syntax mentioned in this benchmark. The implementation is straightforward and follows standard JavaScript practices. **Other alternatives** If you're looking for alternative chunking libraries, some popular options include: * Array.prototype.chunk() (ES6+): This is a built-in array method that can be used to create an array of chunks. * Ramda (or other functional programming libraries): These libraries provide different approaches to array transformations and might offer optimized implementations. Keep in mind that the choice of chunking library or implementation depends on your specific requirements, such as performance, code readability, and maintainability.
Related benchmarks:
native slice vs lodash slice
native slice vs lodash slice 1M
native-slice-vs-chunk
native-splice-vs-chunk
Comments
Confirm delete:
Do you really want to delete benchmark?