Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.has vs. array.includes (300 elements)
(version: 0)
Comparing performance of:
includes vs lookup
Created:
4 years ago
by:
Guest
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, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299]; var b = new Set(a)
Tests:
includes
return a.includes(1000)
lookup
return b.has(1000)
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 provided JSON data and explain what is being tested, compared options, pros and cons of those approaches, and other considerations. **Benchmark Definition** The benchmark definition represents a JavaScript microbenchmark that tests the performance of two different methods: `set.has` and `array.includes`. The benchmark is designed to measure the execution time of these two methods when searching for an element in a large array (`a`) containing 300 elements. **Script Preparation Code** The script preparation code defines two variables: * `a`: an array containing 300 elements, starting from 0 and incrementing by 1. * `b`: a new Set object created from the array `a`. **Html Preparation Code** There is no HTML preparation code provided, which means that the benchmark does not test any specific HTML-related functionality. **Individual Test Cases** The individual test cases represent two separate benchmarks: 1. **`includes`**: Tests the performance of the `array.includes()` method when searching for a specific element (1000) in the array `a`. 2. **`lookup`**: Tests the performance of the `set.has()` method when searching for a specific element (1000) in the Set object `b`. **Comparison of Options** The two methods being compared are: * `array.includes()`: This method searches for an element in an array by iterating through the elements and checking if it matches the specified value. It returns a boolean result indicating whether the element is found. * `set.has()` (or `lookup`): This method searches for an element in a Set object by using a hash table to store the elements and then checking if the specified value exists in the set. **Pros and Cons of Each Approach** Here are some pros and cons of each approach: * `array.includes()`: + Pros: Easy to implement, fast iteration through array. + Cons: Can be slow for large arrays or sparse arrays (arrays with many null or undefined elements). * `set.has()` (or `lookup`): + Pros: Fast lookup times, even for large sets, since it uses a hash table data structure. + Cons: Requires creating a Set object, which can be slower than simply iterating through an array. **Other Considerations** The benchmark assumes that the performance difference between these two methods is significant enough to warrant testing. However, in practice, this might not always be the case, especially for small arrays or sparse arrays. **Alternatives** There are other ways to search for elements in an array or Set object, such as using `indexOf()`, `includes()` (which is similar to `array.includes()`), or even using regular expressions. However, these alternatives may not provide significant performance benefits over the `array.includes()` and `set.has()` methods used in this benchmark. In summary, the provided JSON data represents a JavaScript microbenchmark that tests the performance of two different methods: `array.includes()` and `set.has()`. The benchmark assumes that the performance difference between these two methods is significant enough to warrant testing.
Related benchmarks:
set.has vs. array.includes 3
set.has vs. array.includes bigger sample
set vs array iteration 999
set vs array iteration 9999
Comments
Confirm delete:
Do you really want to delete benchmark?