Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.has vs. array.includes 3
(version: 0)
Comparing performance of:
includes vs has
Created:
5 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199]; var b = new Set(a)
Tests:
includes
return a.includes(180)
has
return b.has(180)
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:
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 provided benchmark and explain what's being tested, along with the pros and cons of different approaches. **Benchmark Definition** The benchmark compares two methods: `a.includes(180)` and `b.has(180)`, where `a` is an array and `b` is a Set. The goal is to determine which method is faster for looking up a specific element (in this case, 180) in the collection. **Script Preparation Code** The script preparation code creates two collections: `a` (an array of numbers from 0 to 200) and `b` (a Set created from `a`). This ensures that both methods are tested on the same data. ```javascript var a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199];\r\nvar b = new Set(a)"; ``` **Html Preparation Code** The HTML preparation code is empty, indicating that no HTML is used in this benchmark. **Individual Test Cases** There are two individual test cases: 1. `includes`: Tests the `a.includes(180)` method. 2. `has`: Tests the `b.has(180)` method. These test cases compare the performance of the two methods on a specific element (180) in their respective collections (`a` and `b`). **Library: Set** The Set library is used to create collection `b`. A Set is an unordered collection of unique values, which makes it useful for fast membership testing. **Pros and Cons** **`includes()`**: * Pros: + Widely supported in modern browsers. + Can be faster than `has()` due to the browser's internal optimizations. * Cons: + Not as efficient as `has()` for large datasets, as it requires a linear search. + May not work as expected in older browsers or with very large datasets. **`has()`**: * Pros: + Generally faster and more efficient than `includes()`, especially for large datasets. + Works well with Set libraries like the one used here. * Cons: + Not as widely supported in older browsers, as it was introduced in ECMAScript 2015 (ES6). + May require additional dependencies or polyfills for older browsers. **Skip Preliminary Observations** The benchmark skips preliminary observations and directly compares the performance of `a.includes(180)` and `b.has(180)`. This is likely due to the fact that the results will depend on the specific data and browser being tested, which makes it challenging to draw general conclusions about the relative performance of these two methods.
Related benchmarks:
set.has vs. array.includes bigger sample
set.has vs. array.includes (300 elements)
set vs array iteration 999
set vs array iteration 9999
Comments
Confirm delete:
Do you really want to delete benchmark?