Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set includes vs array includes size=2
(version: 0)
Comparing performance of:
array (first case) vs array (second case) vs Set (first case) vs Set (second case) vs Set (no case) vs array (no case)
Created:
6 years ago
by:
Guest
Jump to the latest result
Tests:
array (first case)
[1, 2].includes(1);
array (second case)
[1, 2].includes(2);
Set (first case)
new Set([1, 2]).has(1);
Set (second case)
new Set([1, 2]).has(2);
Set (no case)
new Set([1, 2]).has(3);
array (no case)
[1, 2].includes(3);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
array (first case)
array (second case)
Set (first case)
Set (second case)
Set (no case)
array (no case)
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 JavaScript microbenchmark on MeasureThat.net. **Benchmark Definition:** The benchmark measures the performance difference between `includes()` and `has()` methods on arrays and Sets in JavaScript. **Script Preparation Code and HTML Preparation Code:** There are no script preparation code or HTML preparation code provided for this benchmark. This means that the test cases will be executed with the default JavaScript engine settings. **Individual Test Cases:** The benchmark consists of six test cases: 1. `array (first case)`: Tests whether an array includes an element using `includes()`. 2. `array (second case)`: Tests whether an array includes another element using `includes()`. 3. `Set (first case)`: Tests whether a Set contains an element using `has()`. 4. `Set (second case)`: Tests whether a Set contains another element using `has()`. 5. `Set (no case)`: Tests whether a Set does not contain an element using `has()`. This is expected to be faster than the other two cases since it's a false positive. 6. `array (no case)`: Tests whether an array includes an element that is not present, using `includes()`. **Library:** There are no explicit libraries used in these test cases, as the `Set` data structure is built-in to JavaScript. **Special JS Features or Syntax:** These tests do not use any special JavaScript features or syntax. They only utilize standard JavaScript methods (`includes()`, `has()`) and constructs (`Arrays`, `Sets`). **Performance Considerations:** The performance difference between these two approaches will be influenced by various factors, including: * The size of the input array or Set. * The type of data being included (e.g., numbers, strings). * The JavaScript engine being used. * The available CPU resources. **Other Alternatives:** Some alternative methods for checking if an element is present in a collection could be used instead of `includes()` and `has()`, such as: * Using `indexOf()` to search for the element's index. * Creating a custom function to check for presence using bitwise operations. * Utilizing third-party libraries or extensions that provide optimized performance. However, these alternatives may not be supported by all JavaScript engines or browsers, and their performance characteristics may vary depending on the specific use case.
Related benchmarks:
convert to set + set.has vs. array.includes
set vs array lookup
set.has (w/ creation) vs. array.includes
equals vs includes (one value)
Comments
Confirm delete:
Do you really want to delete benchmark?