Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs native, reduce vs zipObject
(version: 0)
Comparing performance of:
lodash zipObject vs lodash reduce vs es6 reduce
Created:
4 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
function double(item, n) { return n*2; } var data = [...Array(20)].map((v, idx) => idx); <script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
function double(item, n) { return n*2; } var data = [...Array(20)].map((v, idx) => idx);
Tests:
lodash zipObject
_.zipObject(data, _.map(double, data))
lodash reduce
_.reduce(data, (acc, cur) => { acc[cur] = double(cur); return acc; }, {});
es6 reduce
data.reduce((acc, cur) => { acc[cur] = double(cur); return acc; }, {});
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash zipObject
lodash reduce
es6 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/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash zipObject
1170491.1 Ops/sec
lodash reduce
4231902.0 Ops/sec
es6 reduce
4361979.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested. **Benchmark Definition** The benchmark is comparing three JavaScript functions: `_.zipObject` from Lodash, and two native implementations of the `reduce` function in ES6 syntax (`data.reduce`). **Options Compared** * `_.zipObject`: A utility function from Lodash that creates a new object by zipping together key-value pairs from multiple arrays. * Native `_.reduce`: The built-in `reduce` method in JavaScript, which applies a user-provided callback function to each element of an array, accumulating a result. **Pros and Cons** * **_.zipObject**: + Pros: Easy to use, concise syntax, well-tested library. + Cons: Adds dependency on Lodash, may have overhead due to library inclusion. * Native `_.reduce` (ES6 syntax): + Pros: No additional dependencies, optimized for performance, intuitive syntax. + Cons: May require more code to achieve the same result as _.zipObject. **Library and Purpose** Lodash is a popular JavaScript utility library that provides a wide range of functions for various tasks, such as array manipulation, object transformation, and more. The `_.zipObject` function is one of its many utilities that helps simplify data processing tasks. **Special JS Feature or Syntax** There is no specific special feature or syntax being tested in this benchmark. Both Lodash's `_.zipObject` and the native ES6 `reduce` functions use standard JavaScript features like arrays and objects. **Other Alternatives** If you need to create a zipped object, other alternatives besides using Lodash's `_.zipObject` include: * Creating an object with a loop or using the `Object.keys()` method. * Using libraries like Ramda (similar to Lodash) or Mochas (another JavaScript utility library). * Implementing your own custom solution using basic JavaScript features. **Benchmark Preparation Code** The provided code sets up a test environment by: 1. Defining a simple function `double(item, n)` that takes an item and a multiplier as arguments. 2. Creating an array `data` with 20 elements, where each element is its index in the array (using `(v, idx) => idx`). 3. Including Lodash's `lodash.min.js` library for the _.zipObject function. **Individual Test Cases** Each test case measures the performance of one specific implementation: 1. `_.zipObject(data, _.map(double, data))`: Measures the time it takes to create a zipped object using Lodash's `_.zipObject`. 2. `data.reduce((acc, cur) => { acc[cur] = double(cur); return acc; }, {})`: Measures the time it takes to create a zipped object using native ES6 `reduce` syntax. 3. `data.reduce((acc, cur) => { acc[cur] = double(cur); return acc; }, {})`: Same as above, but without Lodash's library inclusion. The latest benchmark results show the performance differences between these three implementations on Chrome 128 running on Windows 10.
Related benchmarks:
lodash for-in vs native for-in (lodash version: 4.17.10)
Loop over object: lodash vs Object.entries fork by d9k 2
Loop over object: lodash vs Object.entries 2
Loop over object: lodash vs Object.entries [2]
lodash entries vs object entries
Comments
Confirm delete:
Do you really want to delete benchmark?