<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.5/lodash.min.js"></script>
var person = { name: 'Foo', lastName: 'Bar' };
_.set(person, 'age', 10)
person.age = 10
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Lodash.set | |
Dot notation property setter |
Test name | Executions per second |
---|---|
Lodash.set | 1646497.8 Ops/sec |
Dot notation property setter | 5524331.0 Ops/sec |
Overview of the Benchmark
The provided JSON represents a JavaScript microbenchmark that compares two approaches to set an object property: Lodash's set
function and dot notation (also known as property setter) in plain JavaScript.
What is tested?
The benchmark tests the performance of two different methods:
set
function: This method uses the popular utility library Lodash to set a specific property on an object.person.age = 10
) to directly set a property on the person
object.Options compared
The benchmark compares the performance of these two methods:
set
functionPros and Cons of each approach:
set
function:Library used:
In this benchmark, Lodash is used as a utility library. Specifically, the lodash.set
function is used in one of the test cases. The set
function is designed to provide a safe and convenient way to set properties on objects without using bracket notation or the dot notation syntax directly.
Special JS feature or syntax:
There are no special JavaScript features or syntaxes being tested in this benchmark. Both approaches rely on standard JavaScript syntax.
Other alternatives:
For setting object properties, there are other approaches that could be used instead of Lodash's set
function and dot notation:
person['age'] = 10
){ age: 10 }
)However, these alternatives are not being tested in this specific benchmark.
Benchmark preparation code:
The provided script preparation code defines a simple person
object with properties name
and lastName
, which is used as the test subject for the benchmark. The HTML preparation code includes a reference to Lodash's library, which makes the _set
function available during the benchmark execution.