Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
new Set([x]).has vs [x].includes
(version: 1)
Comparing performance of:
includes vs has
Created:
5 years ago
by:
Registered User
Jump to the latest result
Tests:
includes
return [42].includes(42)
has
return new Set([42]).has(42)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
includes
has
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
includes
29736040.0 Ops/sec
has
1861505.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.1:latest
, generated one year ago):
Let's break down what's being tested and explained. **Benchmark Definition** The benchmark tests the performance of two different methods for checking if an element exists in an array: `includes` and `has`. * **Includes**: This method is used to check if a specified value is present in an array. In this test case, it checks if the number `42` is included in the array `[42]`. * **Has (Set)**: This method uses a Set data structure to check if a value is present in an array. A Set is a collection of unique values. In this test case, it creates a Set from the array `[42]` and then checks if the number `42` is present in that Set. **Test Cases** There are two individual test cases: 1. **includes**: This test case uses the `includes` method to check if the number `42` is present in an array containing only one element, `42`. 2. **has**: This test case uses a Set and the `has` method to check if the number `42` is present in an array containing only one element, `42`. **Library/Feature** No external libraries are used in these test cases. **Other Considerations** * The test cases use vanilla JavaScript (ES5), so no specific version or syntax features are required. * The performance of the two methods (`includes` and `has`) is being compared on different browsers and devices. * No special setup or preparation code is needed to run these test cases. **Alternatives** Other alternatives for checking if an element exists in an array include: * Using a simple loop: `for (var i = 0; i < arr.length; i++) { if (arr[i] === value) return true; }` * Using the `indexOf` method (although it's generally slower than `includes`) * Using a more advanced data structure, such as a Map or an object However, these alternatives are not being tested in this specific benchmark.
Related benchmarks:
convert to set + set.has vs. array.includes
array.includes vs. set.has on the fly
Array includes vs Set.has
set.has (w/ creation) vs. array.includes
Comments
Confirm delete:
Do you really want to delete benchmark?