Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lohash _.has vs JS native hasOwnProperty
(version: 0)
Comparing performance of:
Lodash has vs JavaScript Native hasOwnProperty
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
var person = {name: 'Frederick', lastName: 'Corcino Alejo'};
Tests:
Lodash has
_.has(person, 'name');
JavaScript Native hasOwnProperty
person.hasOwnProperty('name')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash has
JavaScript Native hasOwnProperty
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/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash has
18728764.0 Ops/sec
JavaScript Native hasOwnProperty
57678144.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the benchmark and explain what's being tested, compared options, pros and cons of those approaches, library usage, special JavaScript features or syntax, and alternatives. **Benchmark Overview** The MeasureThat.net benchmark compares the performance of two approaches to check if a property exists in an object: JavaScript native `hasOwnProperty` and Lodash's `_has`. **Test Cases** There are two individual test cases: 1. **Lodash has**: Tests the performance of Lodash's `_has` method. * Benchmark Definition: `_.has(person, 'name');` 2. **JavaScript Native hasOwnProperty**: Tests the performance of JavaScript native `hasOwnProperty` method. * Benchmark Definition: `person.hasOwnProperty('name')` **Library Usage** Lodash is a popular utility library for JavaScript that provides various functions to perform common tasks, such as array manipulation, string manipulation, and object manipulation (including checking if properties exist). In this benchmark, Lodash's `_has` function is used to check if a property exists in an object. **Special JavaScript Features or Syntax** None mentioned in the provided code. However, it's worth noting that some versions of JavaScript have specific syntax for iterating over object properties using `for...in` or `Object.keys()`. This benchmark doesn't use these features explicitly. **Approach Comparison** The two approaches being compared are: 1. **Lodash's `_has` method**: Lodash provides a simple and efficient way to check if a property exists in an object. The `_has` function takes two arguments: the object to search, and the property name. 2. **JavaScript Native `hasOwnProperty` method**: This is a built-in method of JavaScript objects that checks if a given property belongs to the object. **Pros and Cons** Here are some pros and cons of each approach: **Lodash's `_has` method:** Pros: * Simple to use * Efficient (no extra overhead) * Works with any object, not just native JavaScript objects Cons: * Requires an additional library (Lodash) to be included in the test environment * May add unnecessary dependency for some tests **JavaScript Native `hasOwnProperty` method:** Pros: * No additional dependencies required * Built-in method, so no extra overhead * Works with any object that supports this method Cons: * More verbose than Lodash's `_has` * Limited to objects (not arrays or other non-object types) **Other Considerations** When choosing between these two approaches, consider the following factors: * Performance: Both methods have similar performance characteristics. However, since `hasOwnProperty` is a built-in method, it may be slightly faster due to its lower overhead. * Code readability and maintainability: Lodash's `_has` method is generally more readable and easier to understand, especially for those unfamiliar with the native method. **Alternatives** Other approaches to check if a property exists in an object include: 1. Using `in` operator (e.g., `person['name'] in person`) 2. Using `Object.prototype.hasOwnProperty.call(person, 'name')` 3. Using `Array.prototype.includes()` or `Set.prototype.has()`, depending on the context (arrays or sets) These alternatives may have different performance characteristics and trade-offs compared to Lodash's `_has` method and JavaScript native `hasOwnProperty` method.
Related benchmarks:
Comparing performance of: Lodash get vs Native with object checking
lodash has vs hasOwnPropertie
Lodash has vs hasOwnProperty.bind
Lodash.get vs Property dot notation @movlan
Comments
Confirm delete:
Do you really want to delete benchmark?