Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
hasVshasOwnProperty
(version: 0)
performance comparison
Comparing performance of:
Lodash vs Javascript Object vs Plain Javascript
Created:
7 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script>https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.core.js</script>
Script Preparation code:
var obj = { a:{ b:{ c:{ d:{ e: 20 } } } } };
Tests:
Lodash
_.has(obj, 'a.b.c.d.e');
Javascript Object
obj.a.b.c.d.hasOwnProperty('e')
Plain Javascript
!!((((obj.a || ob).b || ob).c || ob).d).e;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash
Javascript Object
Plain Javascript
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to help you understand the benchmark being tested on MeasureThat.net. **What is being tested?** The benchmark tests three different approaches for checking if an object has a specific property with a value: 1. **Lodash**: Using the `_.has()` function from the Lodash library, which checks if an object has a specific property. 2. **JavaScript Object**: Using the `in` operator to check if an object has a specific property, and then using the `.hasOwnProperty()` method to verify that the property is not inherited from a prototype. 3. **Plain JavaScript**: Using a simple expression with the dot notation (`obj.a.b.c.d.e`) to access the nested properties of the object. **Options compared** The three approaches are compared in terms of their performance, measured by the number of executions per second on a specific device (Chrome 85 on a Mac OS X 10.15.5 desktop). **Pros and Cons** Here's a brief summary of the pros and cons of each approach: 1. **Lodash**: * Pros: Easy to use, concise code, fast performance. * Cons: Adds extra library dependency, may not be suitable for all environments. 2. **JavaScript Object**: * Pros: Native implementation, no dependencies required. * Cons: More verbose code, potential performance overhead due to the `in` operator and `hasOwnProperty()` method. 3. **Plain JavaScript**: * Pros: Fastest performance, native implementation. * Cons: Requires more manual effort to implement nested property access. **Library usage** The benchmark uses the Lodash library, which is a popular utility library for functional programming in JavaScript. The `_.has()` function is used to check if an object has a specific property. **Special JS feature or syntax** None of the approaches use any special JavaScript features or syntax that would be unfamiliar to most software engineers. However, it's worth noting that the `in` operator and `hasOwnProperty()` method are part of the ECMAScript standard, so they may not require additional dependencies or setup. **Other alternatives** If you're interested in exploring alternative approaches, here are a few options: * Using a more advanced library like jQuery or Ramda, which offer more features for working with objects. * Implementing custom logic using bitwise operations or other techniques to access nested properties quickly. * Using a different approach, such as using an index-based lookup table or caching the results of previous accesses. Keep in mind that each approach has its trade-offs, and the choice ultimately depends on the specific requirements of your use case.
Related benchmarks:
lodash has vs hasOwnPropertie
ES6 Optional Chaining vs. ES6 Optional Chaining vs. Lodash _.get
Lodash _.has vs Optional Chaining
Lodash has vs Native Javascript
Comments
Confirm delete:
Do you really want to delete benchmark?