Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Setting of intermediate objects
(version: 0)
Testing manual object creation vs. lodash's automatic version.
Comparing performance of:
Native vs lodash
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.5/lodash.min.js"></script>
Script Preparation code:
var value = 'new'; var newPath = 'a.b.c';
Tests:
Native
var newObject = newPath.split('.').reduceRight((obj, part) => ({ [part]: obj }), value);
lodash
var newObject = _.set({}, newPath, value);
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:
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):
Let's break down the provided benchmarking test case. **What is being tested?** The benchmark measures the performance difference between two approaches: 1. **Manual object creation**: This approach creates an object by manually splitting a string into parts and then using `reduceRight` to create an object with those parts as properties. 2. **Lodash's automatic version**: This approach uses Lodash, a popular JavaScript utility library, which provides a function called `set` that automatically creates objects with the specified key-value pairs. **Options being compared** The benchmark is comparing two options: 1. Manual object creation (Native) 2. Using Lodash's `set` function (Lodash) **Pros and cons of each approach:** **Manual Object Creation (Native):** Pros: * No dependency on a third-party library * Control over the creation process * Potential for optimization opportunities Cons: * More verbose code * Requires manual splitting and object creation, which can be error-prone * May not take advantage of compiler optimizations or browser-specific features **Lodash's `set` function (Lodash):** Pros: * Convenient and concise way to create objects with key-value pairs * Reduces boilerplate code * Often provides a better performance profile due to optimized implementation Cons: * Requires an additional dependency on the Lodash library * May introduce overhead due to the library's initialization process * Less control over the creation process compared to manual object creation **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for common tasks, such as string manipulation, array operations, and object creation. The `set` function is part of this library and allows creating objects with key-value pairs in a concise and readable way. **Special JS feature or syntax: None** There are no special JavaScript features or syntax used in this benchmarking test case. **Other alternatives** If you want to avoid using Lodash, you can use other libraries like `merge` functions from React or `Object.assign()` with object destructuring. However, these alternatives may not provide the same level of convenience and performance as Lodash's `set` function. For a native implementation without any external dependencies, you can create objects manually using techniques like: ```javascript function createObject(str) { const parts = str.split('.'); let obj = {}; for (let i = parts.length - 1; i >= 0; i--) { obj[parts[i]] = obj[parts[i]] || {}; } return obj; } ``` Keep in mind that this implementation may not be as performant or concise as Lodash's `set` function.
Related benchmarks:
lodash.keys vs Object.keys
lodash assign vs spread
isEmpty vs Object.keys
Fair Lodash deep clone vs Spread Clone
Comments
Confirm delete:
Do you really want to delete benchmark?