Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native vs lodash newnew
(version: 0)
Comparing performance of:
native vs lodash
Created:
one year 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:
data = { 'meta': { 'pagination': { 'page': 1, 'limit': 10 } }, 'data': { 'id': 123, 'name': 'Example' }, 'errors': 'None' }
Tests:
native
console.log(data && data.meta && data.data && data.errors ? data.data : data)
lodash
console.log(( _.has(data,'meta') && _.has(data,'data') && _.has(data,'errors') ) ? data.data : data)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
native
lodash
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0
Browser/OS:
Chrome 129 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
native
168413.8 Ops/sec
lodash
142348.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks! **What is being tested?** The provided benchmark tests two approaches for accessing nested properties in an object: native JavaScript and Lodash (a popular utility library). The test case uses a JSON object `data` with three properties: `meta`, `data`, and `errors`. The objective is to access the value of `data` only if it exists. The test checks how fast each approach can retrieve this value. **Options being compared:** There are two approaches being compared: 1. **Native JavaScript**: This approach uses the ternary operator (`?`) to check if the property exists and returns `data.data` if it does, or `data` itself if it doesn't. 2. **Lodash (_.has)**: This approach uses the `_.has()` function from Lodash to check if each property exists before accessing it. **Pros and Cons of each approach:** ### Native JavaScript Pros: * Lightweight and efficient * Easy to understand and implement * No external dependencies required Cons: * Can be slower for complex object traversals due to the overhead of the ternary operator * May not work as expected if the object has a large number of properties or nested structures ### Lodash (.has) Pros: * Fast and efficient for complex object traversals * Convenient and concise syntax * Provides additional functionality beyond just property existence checks (e.g., _.has(), _.includes()) Cons: * Requires an external dependency (Lodash) * May have a slight overhead due to the function call **Other considerations:** * For simple cases, the native JavaScript approach may be faster or more suitable. * For complex object traversals, Lodash's `.has()` function is likely to be faster and more efficient. * The benchmark results indicate that the native JavaScript approach outperforms Lodash in this specific test case. **Library description:** The Lodash library provides a set of utility functions for working with JavaScript objects, arrays, and other data structures. In this context, `_.has()` is used to check if an object has a certain property or key. **Special JS feature or syntax:** There are no special features or syntaxes mentioned in the provided benchmark definition. The focus is on comparing two basic approaches for accessing nested properties in JavaScript objects. I hope this explanation helps you understand the JavaScript microbenchmark and its findings!
Related benchmarks:
Direct object access vs _.get
asdasdjkh askjdjkasdkjasd
Direct object array access vs _.get
has vs native last
Comments
Confirm delete:
Do you really want to delete benchmark?