Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs Native reduce on object Copy
(version: 0)
Comparing performance of:
Lodash vs Native
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.4/lodash.min.js"></script>
Script Preparation code:
window.obj = {}; for (var i = 0, len = 10; i < len; i++) { var arr = [] obj['key' + i] = arr for (var n = 0, len = 10; n < len; n++) { arr.push({ ['key' + n]: n }); } }
Tests:
Lodash
_.reduce(obj, (acc, val) => { acc.push(val.map(d => ({ value: val }))); return acc; }, [])
Native
Object.values(obj).reduce((acc, val) => { acc.push(val.map(d => ({ value: val }))); return acc; }, [])
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash
Native
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.1:latest
, generated one year ago):
Let's break down what's being tested and compared in this benchmark. **What's the purpose of this benchmark?** The goal is to compare the performance (speed) of two different approaches for reducing an object with arrays as its values, using either the Lodash library or native JavaScript functions. **What are the test cases?** There are two individual test cases: 1. **Lodash**: This test uses the `_reduce` function from the Lodash library to iterate over the object's values (which are arrays), and for each array, it maps over its elements and pushes a new object with the `value` property set to the original value. 2. **Native**: This test uses the native JavaScript `Object.values()` method to get an array of the object's values, followed by a call to the built-in `reduce` function to iterate over the array, similar to the Lodash implementation. **What library is used?** The Lodash library is used in one of the test cases. Lodash is a popular JavaScript utility library that provides functional programming helpers like `_reduce`, as well as other useful functions for tasks such as data manipulation and string formatting. **What's being compared?** The benchmark compares the performance (Executions Per Second) of these two approaches: using Lodash (`_.reduce`) versus native JavaScript (`Object.values().reduce`). **Pros/Cons of each approach:** * **Lodash (`_.reduce`)**: + Pros: Simplified code, easy to read and understand. + Cons: Requires the addition of a library (~10KB), which can affect page load time and performance. * **Native JavaScript (`Object.values().reduce`)**: + Pros: No additional library needed, which means smaller bundle size and potentially faster execution (in this case). + Cons: More complex code, which might be harder to read and understand for some developers. **Other considerations:** While the benchmark focuses on performance, it's essential to consider other factors when choosing between these approaches: * **Library overhead**: Adding a library like Lodash can introduce an overhead in terms of bundle size and potential performance impact. * **Code maintainability**: If you're working with large codebases or complex data structures, using native JavaScript functions might be more maintainable and easier to understand. * **Development speed**: Choosing the simpler `Lodash` approach might save development time upfront. **Alternatives?** For similar use cases: 1. Use other libraries like Underscore.js (~5KB) or Ramda.js (~15KB), which provide similar functionality to Lodash. 2. Explore native JavaScript functions, such as `Array.prototype.reduce()` (not tested here). 3. Consider using frameworks like React Query or Redux for data management and caching, which can help optimize performance. Feel free to ask if you'd like me to elaborate on any of these points!
Related benchmarks:
Lodash vs Native reduce on object - updated 2
Lodash vs Native reduce + Object.keys for collections
Lodash reduce vs transform vs Native reduce on object
Lodash reduce vs transform vs Native reduce on object (Object without prototype)
Comments
Confirm delete:
Do you really want to delete benchmark?