<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.5/lodash.min.js"></script>
var person = { name: 'Foo', lastName: 'Bar' };
person['age'] = 10
person.age = 10
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Dot notation property setter | |
Lodash.set |
Test name | Executions per second |
---|---|
Dot notation property setter | 253852544.0 Ops/sec |
Lodash.set | 247489136.0 Ops/sec |
I'll break down the provided benchmark and its related details.
Benchmark Overview
MeasureThat.net is used to compare different approaches to set an object property. The website allows users to create and run JavaScript microbenchmarks. In this specific case, we're testing two approaches: dot notation (using a string as a key) and using Lodash's set
function.
Options Compared
We have two options being compared:
lodash.set
function from the Lodash library to set an object property.Pros and Cons of Each Approach
Dot Notation Property Setter:
Pros:
Cons:
Lodash.set:
Pros:
Cons:
Library: Lodash
The lodash.set
function is part of the Lodash library. It's a utility function designed for specific use cases, like setting properties on objects. In this benchmark, it's used as an alternative approach to set object properties.
Lodash provides many other useful functions and methods beyond set
. Some examples include:
cloneDeep
compact
curry
each
Special JS Feature/Syntax
There are no special JavaScript features or syntax mentioned in the benchmark. It solely relies on standard JavaScript and Lodash's set
function.
Alternative Approaches
Other alternatives to set object properties include:
[]
instead of parentheses ()
.While these alternatives exist, the benchmark focuses on comparing dot notation with Lodash's set
function specifically.