Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Direct object access vs _.get
(version: 0)
Comparing performance of:
vanilla vs lodash get
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
dataset = { data: { records: [] } }
Tests:
vanilla
dataset.data.records
lodash get
_.get(dataset, 'data.records')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
vanilla
lodash get
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
vanilla
263538816.0 Ops/sec
lodash get
21458872.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to help explain the JavaScript microbenchmark on MeasureThat.net. **What is being tested?** The benchmark tests two different ways of accessing an object's property in JavaScript: using direct object access (`dataset.data.records`) and using the `_get` function from the Lodash library (`_.get(dataset, 'data.records')`). **Options compared** There are two options being compared: 1. Direct object access (`dataset.data.records`) 2. Using the `_get` function from Lodash (`_.get(dataset, 'data.records')`) **Pros and Cons of each approach** 1. **Direct Object Access** * Pros: + Simple and straightforward * Cons: + May lead to slower performance if the property is accessed in a chain (e.g., `dataset.data.records[0]`) + Less readable code, especially for complex object accesses 2. **Using _get from Lodash** * Pros: + More readable code, as it explicitly states the path to the desired property + Can provide better performance in some cases (e.g., if the property is accessed frequently) * Cons: + Requires an additional library dependency (Lodash) + May add overhead due to function calls **Library: Lodash** The `_get` function from Lodash is a utility function that allows you to safely access nested properties of an object. It takes two arguments: the first argument is the object, and the second argument is a string representing the path to the desired property (e.g., `'data.records'`). The function returns the value of the property at the specified location. **Special JS feature/Syntax** This benchmark does not use any special JavaScript features or syntax. It only uses standard JavaScript and Lodash functions. **Other alternatives** If you prefer to avoid using an external library, you can also consider using other alternatives for accessing nested properties, such as: * Using bracket notation (`dataset['data']['records']`) * Using the `in` operator (`'data.records' in dataset`) * Using a recursive function to access the property (e.g., `function getRecord(dataset) { if (dataset.data.records) return dataset.data.records[0]; else return null; }`) However, these alternatives may have similar pros and cons to using direct object access or `_get` from Lodash.
Related benchmarks:
lodash.keys [4.17.11] vs Object.keys
es6 destructuring vs lodash _.get asjfoasijdfio
Lodash.get vs Property dot notation for complex data
Direct object array access vs _.get
Comments
Confirm delete:
Do you really want to delete benchmark?