Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
in vs hasOwnProperty vs bool vs typeof vs hasOwn
(version: 0)
Comparing performance of:
in vs hasOwnProperty vs hasOwn vs bool vs typeof
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var pages = { "0-0": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-1": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-2": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-3": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-4": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-5": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-6": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-7": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-8": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-9": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-10": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-11": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-12": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-13": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-14": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-15": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-16": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-17": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-18": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-19": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-20": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-21": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-22": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }, "0-23": { "programs": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] } }
Tests:
in
"0-12" in pages
hasOwnProperty
pages.hasOwnProperty("0-12")
hasOwn
Object.hasOwn(pages, "0-12")
bool
!!pages["0-12"]
typeof
typeof pages["0-12"] !== "undefined"
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
in
hasOwnProperty
hasOwn
bool
typeof
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):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Definition** The benchmark is testing four different ways to check if a key exists in an object: `in`, `hasOwnProperty`, `hasOwn`, and `!!`. The `!!` operator is used to convert the result of the expression to a boolean value. **Individual Test Cases** There are four test cases, each representing one of the four methods: 1. **"0-12" in pages**: This test case uses the `in` operator to check if the key "0-12" exists in the `pages` object. 2. **`pages.hasOwnProperty("0-12")`**: This test case uses the `hasOwnProperty` method of the `pages` object to check if the key "0-12" is a direct property of the object. 3. **`Object.hasOwn(pages, "0-12")`**: This test case uses the `hasOwn` method of the `Object` class to check if the key "0-12" exists in the `pages` object as a direct property. 4. **`!!pages["0-12"]`**: This test case uses the `!!` operator to convert the result of accessing the key "0-12" in the `pages` object to a boolean value (true if the key exists, false otherwise). **Test Results** The latest benchmark results show that: * The `typeof` method is the fastest (executions per second: 33384584.0) * The `!!` operator is almost as fast as `typeof` (executions per second: 33215608.0) * The `bool` test case (using the `!!` operator) is slower than the top two (executions per second: 24228030.0 and 10034139.0) * The `hasOwnProperty` method is slower than the `in` operator (executions per second: 33340628.0 vs. 33384584.0) * The `hasOwn` method is the slowest (executions per second: 10034139.0) **What's being tested** The benchmark is testing the performance of four different methods for checking if a key exists in an object. The results show that the `in` operator and the `!!` operator are relatively fast, while the `hasOwnProperty` method and the `hasOwn` method are slower. This suggests that the `in` operator and the `!!` operator are more efficient ways to check for key existence in objects.
Related benchmarks:
splice vs length
splice vs length 2
Large containers non existing Array.includes vs Set.has vas Map.has
Lodash isEqual vs JSON stringify v2
Comments
Confirm delete:
Do you really want to delete benchmark?