Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.has vs. array.includes big data
(version: 0)
Comparing performance of:
includes vs lookup
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = [...Array(10000).keys()]; var b = new Set(a)
Tests:
includes
return a.includes(5000)
lookup
return b.has(5000)
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 explain what's being tested. **Overview** The benchmark measures the performance difference between two approaches: `array.includes()` and `set.has()`. The test uses a large array of 10,000 elements to simulate big data. **Options Compared** The two options being compared are: 1. **`array.includes()`**: This method searches for a specific value (in this case, the number 5000) within an array. It returns `true` if the value is found and `false` otherwise. 2. **`set.has()`**: This method checks if a specific value exists in a Set object. In this benchmark, the Set contains all elements from the large array. **Pros and Cons of Each Approach** 1. **`array.includes()`**: * Pros: Simple to implement, widely supported by browsers. * Cons: Can be slower for large datasets due to the linear search algorithm. 2. **`set.has()`**: * Pros: Generally faster for large datasets since Sets use a more efficient data structure (hashing). * Cons: Requires creating a Set object, which can incur additional memory overhead. **Library and Purpose** In this benchmark, the `Set` library is used to create a Set object from the large array. The purpose of using a Set is to provide an alternative data structure that allows for efficient membership testing. **Special JS Feature or Syntax** There are no special JavaScript features or syntaxes being tested in this benchmark. **Other Alternatives** If you want to explore other alternatives, here are some options: 1. **`Array.prototype.findIndex()`**: This method returns the index of the first element that matches the specified value (in this case, 5000). If no match is found, it returns -1. 2. **`Map.has()`**: Similar to `set.has()`, but using a Map object instead. These alternatives can be used in similar scenarios where you need to search for a specific value within an array or dataset. Keep in mind that the choice of alternative depends on your specific use case and performance requirements.
Related benchmarks:
set.has vs. array.includes (1kkk)
Array includes set has
set.has vs. array.includes (large)
set.has vs. array.includes (find 999,999 in 1,000,000)
Comments
Confirm delete:
Do you really want to delete benchmark?