Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.has vs. array.includes(million)
(version: 0)
Comparing performance of:
includes vs lookup
Created:
4 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var a = new Array(10000).map((item,index)=>index); var b = new Set(a)
Tests:
includes
return a.includes(9999)
lookup
return b.has(9999)
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:
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 benchmark and its options. **Benchmark Definition** The benchmark is designed to compare two methods for checking if an element exists in a large array (`a`) or a set (`b`): `array.includes()` vs `set.has()`. **Options Compared** There are two options compared: 1. **Array.includes()**: This method checks if an element exists in the array by iterating through its elements and checking for a match. 2. **Set.has()**: This method checks if an element exists in the set by using a hash table data structure to store unique values. **Pros and Cons** Here are some pros and cons of each approach: * **Array.includes()**: + Pros: Easy to implement, works well for small arrays. + Cons: Slow for large arrays due to linear search, may be optimized away in some browsers. * **Set.has()**: + Pros: Fast for large datasets, uses a hash table data structure for efficient lookups. + Cons: Requires creating a set from the array, which can be slower than initializing an empty array. **Library** In this benchmark, `Set` is used as a library to create a set from the array. The `Set` constructor takes an iterable (in this case, an array) and automatically adds each unique element to the set. **Special JS Feature/Syntax** This benchmark uses none of any special JavaScript features or syntax beyond standard ES6/ES7 syntax. It's designed to be run in a variety of browsers with different levels of support for modern features. **Other Considerations** * The benchmark is designed to measure performance, so it's essential to consider factors like cache locality and branch prediction when interpreting the results. * The test cases are written to exercise specific aspects of each method, ensuring that the comparison is fair and representative. **Alternatives** If you wanted to explore alternative approaches or testing scenarios: 1. Compare `includes()` with a custom implementation using binary search or other optimized algorithms. 2. Test `has()` against other set operations like `delete()` or `size()`. 3. Use different data distributions (e.g., random numbers, strings) for the test array or set. Keep in mind that these alternatives would require adjustments to the benchmark definition and script preparation code.
Related benchmarks:
set.has vs. array.includes 2
set.has vs. array.includes on 25 000 items
set.has vs. array.includes (find 999,999 in 1,000,000)
Array.includes vs Set.has vas Map.has 2
Comments
Confirm delete:
Do you really want to delete benchmark?