Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash Flatten vs Array.flat()
(version: 0)
lodash flatten vs spread
Comparing performance of:
array flat vs lodash flatten
Created:
2 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>
Tests:
array flat
const arrayA = ['hi', 'hi', 'hi', 'hi']; const arrayB = ['hi', 'hi', 'hi', 'hi']; const flattened = [ arrayA, arrayB ].flat(); console.log(flattened);
lodash flatten
const arrayA = ['hi', 'hi', 'hi', 'hi']; const arrayB = ['hi', 'hi', 'hi', 'hi']; const flattened = _.flatten([arrayA, arrayB]); console.log(flattened);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
array flat
lodash flatten
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0
Browser/OS:
Chrome 143 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array flat
283126.8 Ops/sec
lodash flatten
258273.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is tested, compared options, pros and cons, library usage, special JavaScript features or syntax, and other considerations. **Benchmark Overview** The test compares two approaches to flatten arrays in JavaScript: using the built-in `Array.flat()` method versus using the Lodash library with its `_flatten()` function. **Options Compared** 1. **Array.flat()**: This is a built-in JavaScript method introduced in ECMAScript 2019, which allows you to flatten an array or array-like object by recursively calling itself on each element that is also an array. 2. **Lodash _flatten()**: Lodash is a popular utility library for functional programming in JavaScript. Its `_flatten()` function takes an array as input and returns a new flattened array. **Pros and Cons** 1. **Array.flat()**: * Pros: Native performance, low memory usage, easy to use. * Cons: Only supported in ECMAScript 2019 and later browsers/engines, may have slower performance for very large arrays. 2. **Lodash _flatten()**: * Pros: Wide browser support (thanks to the included Lodash library), supports older JavaScript versions, potentially faster for larger arrays due to optimized implementation. * Cons: Requires an additional library download and potential performance overhead. **Library Usage** In this benchmark, the Lodash library is used with its `_flatten()` function. Lodash is a popular utility library that provides many functional programming helpers, including flattening arrays. **Special JavaScript Features or Syntax** None mentioned in the provided test case. **Other Considerations** 1. **Browser Support**: The benchmark runs on Chrome 128, which supports ECMAScript 2019 and later features. 2. **Device Platform**: The device is a desktop computer, which may impact performance compared to mobile devices. 3. **Operating System**: The operating system is Windows, which may also affect performance. **Alternatives** Other alternatives for flattening arrays in JavaScript include: 1. Using the `Array.prototype.concat()` method with an array of arrays. 2. Using a recursive function to manually flatten the array. 3. Using other libraries or frameworks that provide similar flattening functionality (e.g., Ramda). Keep in mind that these alternatives may have different performance characteristics and usage scenarios compared to Array.flat() and Lodash _flatten().
Related benchmarks:
array flat vs _.flatten
Array immutable union: lodash union vs flatten and creating a new set
Lodash flatten vs nativate flat (depth 1)
Lodash Flatten vs Array.flat() with infinite
Lodash flattern vs flat
Comments
Confirm delete:
Do you really want to delete benchmark?