Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.has vs. Object key lookup vs array.includes
(version: 0)
Comparing performance of:
set.has vs key lookup vs array.includes
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = new Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); var b = {1: true, 2: true, 3: true, 4: true, 5: true, 6: true, 7: true, 8: true, 9: true, 10: true} var c = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
Tests:
set.has
return a.has(9)
key lookup
return b['9']
array.includes
return c.includes(10);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
set.has
key lookup
array.includes
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 JSON data and explain what is being tested, compared, and considered. **Overview** The benchmark measures the performance of three different approaches to access elements in a data structure: 1. `Set.has`: Using the `has` method on a `Set` object. 2. `Object key lookup`: Looking up an element by its key using square bracket notation (`[key]`) on an object. 3. `Array.includes`: Checking if an element exists in an array using the `includes` method. **Options Compared** The three options are compared in terms of their execution speed, measured in executions per second (EPS). * **Set.has**: The `has` method is used to check if a value exists in the set. This approach is likely to be faster since sets are optimized for fast lookups. * **Object key lookup**: This approach uses square bracket notation (`[key]`) to access an element by its key. This can lead to slower performance since it involves a lookup and possibly a creation of a new object reference. * **Array.includes**: The `includes` method is used to check if an element exists in the array. This approach may be faster than using square bracket notation, but its performance can vary depending on the specific implementation. **Pros and Cons** * **Set.has**: Pros: + Fast lookups + Optimized for sets + Simple syntax Cons: + May not work correctly with non-integer values or objects * **Object key lookup**: Pros: + Works with any data type that can be used as a key + Flexibility Cons: + Slower performance compared to `Set.has` + Requires square bracket notation, which may lead to additional memory allocations. * **Array.includes**: Pros: + Works with arrays of integers or strings + May be faster than object key lookup for certain use cases Cons: + May be slower than `Set.has` for large sets + Can lead to additional memory allocations if the array is not properly optimized. **Library and Purpose** In the provided benchmark, no external libraries are used. However, sets are a built-in JavaScript data structure that provides an efficient way to store unique values and perform lookups. **Special JS Features or Syntax** None of the test cases use special JavaScript features or syntax beyond what is commonly used in everyday development.
Related benchmarks:
Includes (array) vs Has (Set)
set.has vs. Object key lookup for real without bang bang
set.has vs. Object key
set.has vs. Object key in lookup
array.includes vs. set.has on the fly
Comments
Confirm delete:
Do you really want to delete benchmark?