Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.has vs. array.includes - large dataset
(version: 0)
Comparing performance of:
includes vs lookup
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = []; for (i = 0; i < 100000; i++) { a.push(i+1); } 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:
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 what's being tested in the provided benchmark. The benchmark is testing two different approaches to check if an element exists within a dataset: 1. `array.includes()`: This method checks if a specified value (in this case, 9) exists as an element within the array `a`. 2. `Set.has()`: This method checks if a specified value (in this case, 9) exists as an element within the Set object `b`, which is created from the array `a`. **Options Comparison** The two options being compared are: * `array.includes()`: This approach uses the JavaScript array method to check for the existence of an element. It iterates through the elements of the array and returns a boolean value indicating whether the specified value exists. * `Set.has()`: This approach uses the JavaScript Set data structure, which is a collection of unique values. When you call `has()` on a Set object, it checks if the specified value exists in the Set. **Pros and Cons** * **array.includes()**: + Pros: Easy to implement, widely supported across browsers. + Cons: Can be slow for large datasets due to the iteration process. * **Set.has()**: + Pros: Fast lookup times, efficient data structure for unique values. + Cons: Requires creating a Set object from the dataset, which can be memory-intensive. **Other Considerations** In this benchmark, the test case is using a large dataset (100,000 elements) to stress-test both approaches. The use of a Set object (`b`) is likely chosen to take advantage of its fast lookup times. **Library and Purpose** No external libraries are used in this benchmark. **Special JS Feature or Syntax** The benchmark does not use any special JavaScript features or syntax that's not standard across browsers. **Alternative Approaches** Other alternatives for checking if an element exists within a dataset include: * Using the `in` operator: `x in array` (not as efficient as `includes()` or Set-based approaches) * Using a regular expression with the `test()` method: `regex.test(array)` (not as efficient as `includes()` or Set-based approaches) * Using a custom implementation, such as iterating through an object's properties using `for...in` loops. Keep in mind that these alternative approaches may not be as widely supported across browsers as the `includes()` and Set-based methods.
Related benchmarks:
set.has vs. array.includes - large dataset - middle result
set.has vs. array.includes - large array
set vs array iteration 100k elements
3set vs array iteration New doge333
Comments
Confirm delete:
Do you really want to delete benchmark?