Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs Native reduce on object 2
(version: 0)
Comparing performance of:
Lodash vs Native
Created:
7 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 = 100; i < len; i++) { var arr = [] obj['key' + i] = arr for (var n = 0, len = 100; n < len; n++) { arr.push({ ['key' + n]: n }); } }
Tests:
Lodash
_.reduce(obj, (acc, val, key) => { acc[key] = val.map(d => ({ label: key, value: val })); return acc; }, {})
Native
Object.entries(obj).reduce((acc, [key, val]) => { acc[key] = val.map(d => ({ label: key, 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.2:3b
, generated one year ago):
I'd be happy to explain the benchmarking test for you. **What is tested:** The provided JSON represents two JavaScript microbenchmarks that compare the performance of Lodash's `reduce` function with the native JavaScript array reduction method. The tests measure how long it takes to iterate over an object and transform its values using these two approaches. **Options compared:** 1. **Lodash's `reduce` function**: A third-party library that provides a convenient way to reduce arrays and objects. 2. **Native JavaScript array reduction method**: Built-in JavaScript functionality that reduces arrays by iterating over their elements. **Pros and Cons of each approach:** **Lodash's `reduce` function:** Pros: * Convenient and readable syntax * Supports various array and object iteration methods (e.g., `forEach`, `map`) * Ecosystem-wide support, as it is widely used in other libraries and frameworks Cons: * Adds an extra dependency (the Lodash library) to the test environment * May introduce additional overhead due to the need for string manipulation and function calls **Native JavaScript array reduction method:** Pros: * No dependencies or overhead added to the test environment * Optimized for performance, as it leverages low-level language features Cons: * Requires more verbose syntax and careful attention to iteration details * May not be as convenient or readable for complex transformations **Other considerations:** * The tests use a large object (`window.obj`) with 100 nested arrays, which may affect the results. This could also be seen as an overkill for most practical scenarios. * Both approaches require the `window.obj` to be populated before running the test. **Library and syntax used in the benchmark:** Lodash is a popular JavaScript utility library that provides various functions for working with data structures, including arrays and objects. The `reduce` function is one of its flagship methods, allowing you to reduce arrays or objects by applying a transformation to each element. The tests use Lodash version 4.17.4, which is an older but still widely supported version. **Special JS features or syntax:** None are explicitly mentioned in the benchmark, but it does utilize some advanced JavaScript concepts: * `for...of` loops for iterating over arrays * Arrow functions (`=>`) and template literals (`\r\n`) for concise code Overall, these tests provide a clear comparison between two approaches to reducing arrays and objects in JavaScript.
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?