Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
chunk test
(version: 0)
Comparing performance of:
native vs lodash
Created:
3 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js'></script>
Script Preparation code:
var array = [ { 'name': 'lim', 'age': 26 }, { 'name': 'kim', 'age': 28 }, { 'name': 'choi', 'age': 32 }, { 'name': 'park', 'age': 21 } ]; var chunk = (input, size) => { return input.reduce((arr, item, idx) => { return idx % size === 0 ? [...arr, [item]] : [...arr.slice(0, -1), [...arr.slice(-1)[0], item]]; }, []); };
Tests:
native
chunk(array, 2)
lodash
_.chunk(array, 2)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
native
lodash
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/29.0 Chrome/136.0.0.0 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 136 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
native
4640815.0 Ops/sec
lodash
24355288.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Overview** The benchmark measures the performance of two approaches to chunking an array into smaller sub-arrays: one implemented in native JavaScript (without any external library) and another using the popular utility library Lodash. **What is Chunking?** Chunking an array involves splitting it into smaller, equal-sized sub-arrays. The goal of this benchmark is to determine which implementation is faster for chunking arrays of a specified size. **Options Compared** There are two options being compared: 1. **Native JavaScript**: This approach uses native JavaScript functions and variables to implement the chunking algorithm. 2. **Lodash**: This approach uses the Lodash library, specifically the `chunk` function from the `lodash` module. **Pros and Cons of Each Approach** **Native JavaScript:** Pros: * Lightweight and self-contained * No dependencies on external libraries * Potential for better cache locality and performance Cons: * May require more manual optimization and tuning * Limited to basic JavaScript features and syntax **Lodash:** Pros: * Leverages optimized, battle-tested implementation from a popular library * Simplifies the chunking algorithm with a well-known function name * Easier maintenance and updates due to the existing community support Cons: * Adds an external dependency (the Lodash library) * May introduce overhead due to the added complexity **Other Considerations** The benchmark also includes information about the device platform, operating system, and browser being used. This data can be useful in understanding how different environments affect performance. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a collection of helper functions for common tasks, such as array manipulation, string manipulation, and more. The `chunk` function from Lodash splits an array into smaller sub-arrays of a specified size. **Special JS Feature or Syntax (None)** There are no special JavaScript features or syntax used in this benchmark that require explanation. **Alternatives** Other alternatives for chunking arrays include: * Using the `Array.prototype.slice()` method with arithmetic indexing * Implementing a custom, hand-rolled algorithm using bitwise operations and loops * Utilizing a third-party library like Ramda or Underscore.js (in addition to Lodash) Keep in mind that these alternatives may have varying levels of performance, readability, and maintainability compared to the native JavaScript implementation and Lodash.
Related benchmarks:
lodash vs es6 in reduce method
Lodash Chunk vs Native Reduce
Chunk - lodash vs javascript vs for loop vs reduce
native-slice-vs-chunk KE2
Comments
Confirm delete:
Do you really want to delete benchmark?