<script src="https://cdn.jsdelivr.net/lodash/4.16.0/lodash.min.js"></script>
var person = {name: { something: { else: 'Frederick' } }, lastName: 'Corcino Alejo'};
_.get(person, 'name.something.else');
person.name.something.else
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Lodash get | |
Native |
Test name | Executions per second |
---|---|
Lodash get | 4673139.5 Ops/sec |
Native | 734800960.0 Ops/sec |
Let's break down what's being tested in the MeasureThat.net benchmark.
The benchmark compares two approaches to accessing nested properties in JavaScript:
get
function takes an object and a path as arguments and returns the value at that path.person
object.What's being tested:
The benchmark is testing which approach (Lodash.get or Native Property Access) performs better in terms of speed, specifically with longer paths (e.g., "name.something.else").
Pros and Cons:
Library Considerations:
Lodash is a popular utility library that provides various functions for working with JavaScript objects. The get
function is particularly useful when you need to dynamically access nested properties on an object.
Special JS Feature/ Syntax:
This benchmark does not use any special JavaScript features or syntax, such as async/await, generators, or ES6+ classes.
Other Alternatives:
If you don't want to use Lodash, you can also consider other alternatives for accessing nested properties in JavaScript, such as:
Object.prototype.hasOwnProperty.call
or in
operator.Keep in mind that these alternatives may have different performance characteristics compared to using Lodash or native property access.