Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.has vs. array.includes
(version: 0)
Comparing performance of:
includes vs lookup
Created:
6 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; var b = new Set(a)
Tests:
includes
return a.includes(9)
lookup
return b.has(9)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
includes
lookup
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
8 days ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:148.0) Gecko/20100101 Firefox/148.0
Browser/OS:
Firefox 148 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
includes
70940320.0 Ops/sec
lookup
1644700544.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its test cases. **Benchmark Overview** The benchmark is comparing two approaches: `set.has` vs. `array.includes`. The goal is to measure which approach is faster for searching an element in a set or array. **Options Compared** The two options being compared are: 1. **Set Has**: This method uses the `has` method of a Set data structure, which returns a boolean value indicating whether the specified element exists in the set. 2. **Array Includes**: This method uses the `includes` method of an Array data structure, which returns a boolean value indicating whether the specified element exists in the array. **Pros and Cons** * **Set Has**: Pros: + Efficient for searching unique elements (e.g., no duplicates). + Fast lookup time due to hash table implementation. Cons: + May not work well for large datasets or arrays with many duplicate elements. * **Array Includes**: Pros: + Works well for large datasets and arrays with many duplicate elements. + More intuitive syntax than Set Has. Cons: + Slow lookup time compared to Set Has due to linear search. **Library and Purpose** In the benchmark, a Set library is used. A Set is a data structure that stores unique elements in a hash table format. The `has` method of a Set allows for fast lookup of an element by its value. **Special JS Feature or Syntax (None)** There are no special JavaScript features or syntaxes being tested in this benchmark. **Other Alternatives** If you were to implement a similar benchmark, you might also consider testing: 1. **Map Lookup**: Similar to Set Has, but uses the `has` method of a Map data structure. 2. **Array Binary Search**: An alternative approach to Array Includes that uses binary search for faster lookup times. Keep in mind that this benchmark is likely designed to test the performance of searching an element in a set or array, which may have different use cases and optimizations compared to other JavaScript scenarios.
Related benchmarks:
convert to set + set.has vs. array.includes
Includes (array) vs Has (Set)
set vs array find if exists
array.includes vs. set.has on the fly
Array includes vs Set.has
Comments
Confirm delete:
Do you really want to delete benchmark?