Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Dot property set notation VS Lodash.set
(version: 1)
Compares different approaches to set an object property
Comparing performance of:
Dot notation property setter vs Lodash.set
Created:
8 years ago
by:
Registered User
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 person = { name: 'Foo', lastName: 'Bar' };
Tests:
Dot notation property setter
_.set(person, 'age', 10)
Lodash.set
person.age = 10
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Dot notation property setter
Lodash.set
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
Dot notation property setter
20882676.0 Ops/sec
Lodash.set
137567200.0 Ops/sec
Autogenerated LLM Summary
(model
gemma2:9b
, generated one year ago):
This benchmark compares two ways of setting a property on an object in JavaScript: * **`_.set(person, 'age', 10)`:** This uses the `set` method from the Lodash library. Lodash is a popular library that provides utility functions for working with JavaScript objects and arrays. The `set` method allows you to set a property on an object, even if the path to that property involves nested objects. * **`person.age = 10`:** This uses the standard dot notation for setting properties in JavaScript objects. **Pros and Cons:** * **Lodash.set:** * **Pros:** Can handle deeply nested objects with ease, potentially more efficient for complex scenarios. * **Cons:** Requires including the Lodash library, which adds to the bundle size. * **Dot notation:** * **Pros:** Simple and familiar, no external dependencies. * **Cons:** Can be less efficient for deeply nested objects, might involve multiple property accesses if the path is complex. **Other Considerations:** * **Performance:** The benchmark results show that `_.set` is faster in this specific case. However, performance differences might be more significant with larger or more complex objects. * **Readability:** Dot notation is generally considered more readable for simple property assignments. * **Use Case:** If you frequently work with deeply nested objects or need advanced object manipulation features, Lodash can be a valuable tool. For simpler scenarios, dot notation is likely sufficient. **Alternatives:** * Other libraries like Ramda offer similar functionality to Lodash's `set`. * Manually traversing the object structure using `for...in` loops or recursion could be an alternative, but it often leads to less readable code and might not be as performant. Let me know if you have any other questions!
Related benchmarks:
Dot property set notation VS Lodash.set poop
property assign VS Lodash.set
Dot property set notation VS Lodash.set (fix)
Dot property set notation VS Lodash.set (initial attribute existing 2)
Comments
Confirm delete:
Do you really want to delete benchmark?