Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array includes vs set has
(version: 0)
Comparing performance of:
Array.includes vs Set.has
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var array = [ 'auto', 'shrink', 'no-shrink', 'grow', 'no-grow', 'no-flex', ]; var aSet = new Set(array);
Tests:
Array.includes
var b = array.includes('no-flex') var c = array.includes('boop')
Set.has
var b = aSet.has('no-flex') var c = aSet.has('boop')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array.includes
Set.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. **What is being tested?** The provided JSON represents two JavaScript microbenchmarks that compare the performance of `includes` method in arrays versus the `has` method on Sets. The tests are designed to measure which approach (array `includes` or Set `has`) is faster. **Options compared:** 1. **Array `includes`**: This method checks if a specified value exists within an array. 2. **Set `has`**: This method checks if a specified value exists within a Set data structure. **Pros and Cons of each approach:** * **Array `includes`**: + Pros: - Well-supported in most modern browsers. - Easy to use and understand. + Cons: - May be slower for large datasets due to the need to iterate through the array. - Can be less efficient if the dataset is not sorted or has duplicate values. * **Set `has`**: + Pros: - Generally faster than `includes` for large datasets, as it uses a hash table for lookups. - More efficient when dealing with unique values or sets of data. + Cons: - Requires the Set object to be created from an array, which can be slower if not done efficiently. - Not all browsers support Sets (although most modern ones do). **Library and purpose:** The `Set` object is a built-in JavaScript API that provides a collection of unique values. It's used here as a data structure to compare with arrays. **Special JS features/syntax:** None mentioned in the provided benchmark definition. **Other alternatives:** For array lookups, other approaches could include: * Using `Array.prototype.indexOf()` (which returns -1 if not found) * Using `Array.prototype.includes()` (which is similar to `includes` but more concise) * Implementing a custom binary search algorithm For Set-based lookups, other alternatives might be: * Using a different data structure like a Map or an object * Using a third-party library that provides optimized Set operations Keep in mind that these alternatives may not offer significant performance improvements over the tested `includes` and `has` methods. The provided benchmark seems to focus on comparing the native JavaScript `includes` and `has` methods, making it a great starting point for testing and exploring different approaches.
Related benchmarks:
set vs array includes
set vs array
Array.from vs. ... expansion
Array includes vs Set.has
new set vs array includes
Comments
Confirm delete:
Do you really want to delete benchmark?