Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.has vs. array.includes with large data
(version: 0)
Comparing performance of:
includes vs has
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var itemsQtty = 100000; var a = []; for (let i = 1; i <= itemsQtty; i++) { a.push(i.toString()); } var b = new Set(a);
Tests:
includes
return a.includes(9)
has
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
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 its test cases. **Benchmark Description** The benchmark is designed to compare the performance of two JavaScript methods: `Set.has()` and `Array.includes()`. The benchmark tests these methods on a large dataset, specifically when searching for a specific value (in this case, the number 9) within the dataset. **Script Preparation Code** The script preparation code creates an array `a` with 100,000 elements, each containing a string representation of a number from 1 to 100,000. The resulting array is then passed to a `Set` object, which is used to create a set `b`. This setup ensures that the benchmark tests both methods on a large dataset. **Html Preparation Code** The html preparation code is empty in this case, indicating that no HTML-related code needs to be executed before running the benchmark. This might be due to the fact that the benchmark focuses solely on JavaScript performance. **Test Cases** There are two individual test cases: 1. **`includes`**: This test case measures the performance of `Array.includes()` when searching for a specific value (9) within the array. 2. **`has`**: This test case measures the performance of `Set.has()` when searching for a specific value (9) within the set. **Library and Purpose** * In both cases, no external library is used to facilitate the benchmarking process. * The `Set` object is a built-in JavaScript data structure that stores unique values. Its primary purpose is to provide fast lookup, insertion, and deletion of elements. **Special JS Feature/Syntax** There are no special JavaScript features or syntax used in this benchmark. Now, let's discuss the pros and cons of each approach: * **`Array.includes()`**: + Pros: Fast and efficient for searching a specific value within an array. + Cons: May have performance issues when dealing with very large arrays due to the need to iterate through the elements. * **`Set.has()`**: + Pros: Fast and efficient for searching a specific value within a set, especially when compared to linear searches in arrays. + Cons: May require more memory to store the set, which can be a concern for very large datasets. **Other Alternatives** If you want to compare performance of other JavaScript methods, here are some alternatives: * **`Array.indexOf()`**: Similar to `includes()`, but returns the index of the first occurrence instead of a boolean value. * **`Set.size`**: Can be used to measure the size of the set, but it's not as efficient as `has()` for searching specific values. * **`Map.get()`**: A dictionary-like data structure that allows fast lookups by key. It can be used in place of `Set.has()`, but may require more memory and have different performance characteristics. Keep in mind that the choice of method depends on the specific use case and requirements. This benchmark provides a good starting point to compare the performance of `Array.includes()` and `Set.has()` for searching specific values within large datasets.
Related benchmarks:
set.has vs. array.includes large
set.has vs. array.includes large 1
set.has vs. array.includes (1 million entries)
set.has vs. array.includes - large array
Comments
Confirm delete:
Do you really want to delete benchmark?