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
llama3.1:latest
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **What is being tested?** The provided JSON represents a benchmark that compares two different approaches to set an object property: 1. **Dot notation property setter**: This approach uses the dot notation syntax, where you access and modify an object property using its name: `person.age = 10`. 2. **Lodash.set**: This approach utilizes the `_.set()` function from the Lodash library, which is a popular utility library for JavaScript. **What options are compared?** Two test cases are being run: 1. `_.set(person, 'age', 10)` (using Lodash.set) 2. `person.age = 10` (using dot notation property setter) These two approaches are essentially setting the value of the `age` property on an object called `person`. **Pros and Cons:** * **Dot notation property setter**: This approach is simple, straightforward, and native to JavaScript. It's also very efficient in terms of execution time. + Pros: - Easy to read and write - No external library dependency + Cons: - Can be prone to typos or incorrect property names * **Lodash.set**: This approach uses a utility function from Lodash, which provides additional functionality for setting object properties in a more robust way. + Pros: - Robustness: protects against typos and incorrect property names - Additional features (e.g., deep-set, etc.) + Cons: - External library dependency (Lodash) - Slightly slower execution time compared to dot notation **Library: Lodash** The Lodash library is a popular utility library for JavaScript that provides a set of functional programming helpers and iterators. In this case, the `_.set()` function is used to set an object property in a more robust way. **Special JS feature or syntax: None** No special JavaScript features or syntax are being used in this benchmark. The code is straightforward and follows standard JavaScript conventions. **Other alternatives:** There are other ways to set object properties in JavaScript, such as: 1. **Bracket notation**: `person['age'] = 10` 2. **ES6 computed property names**: `{ age: 10 }` (in an object literal) 3. **Object.assign()**: `Object.assign(person, { age: 10 })` These alternatives are not compared in this benchmark, but they can be used in other contexts to achieve similar results. Overall, this benchmark provides a simple and effective way to compare different approaches to setting object properties in JavaScript.
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?