Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.include vs Set.has
(version: 0)
Comparing performance of:
Includes vs Some vs Set
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var array = ['banana', 'sausage', 'jesus'] var s = new Set(array)
Tests:
Includes
array.includes('sausage')
Some
array.some(v => v === 'sausage')
Set
s.has('sausage')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Includes
Some
Set
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 benchmark and its test cases. **What is being tested?** The provided JSON represents a JavaScript microbenchmark that compares the performance of three different approaches to check if an element exists in an array or set: 1. `array.includes()` (or `array.includes('sausage')` in this specific test case) 2. `some()` 3. `Set.has()` (or `s.has('sausage')` in this specific test case) **Options compared:** The three options being compared are: * `includes()`: a method on arrays that checks if an element exists within the array. * `some()`: a method on arrays that returns true as soon as at least one element in the array passes the test implemented by the provided function. * `Set.has()`: a method on sets that checks if an element exists within the set. **Pros and Cons of each approach:** 1. **`array.includes()`**: * Pros: + Widely supported across browsers + Fast, as it uses a binary search algorithm * Cons: + May not be as efficient for very large arrays or sets 2. **`some()`**: * Pros: + Can short-circuit if the array is empty or has no matching elements + Can be more memory-efficient than `includes()` in some cases * Cons: + May not be as widely supported across browsers (though this is improving) + May have a slight performance hit due to the need to iterate over the array 3. **`Set.has()`**: * Pros: + Fast, as it uses a hash table internally for lookups + Memory-efficient, as it only stores unique elements * Cons: + Requires an underlying set object (which may not be supported in all browsers) + May require more overhead to create the set and perform lookups **Library usage:** In this benchmark, a `Set` library is used to create a set from an array. The purpose of this library is to provide an efficient way to store unique elements. **Special JavaScript features or syntax:** There are no special JavaScript features or syntax being tested in this benchmark. Now, let's look at the test cases and their results: The test cases are designed to measure the performance of each approach: * "Includes" measures the time it takes to use `array.includes()` with a specific element. * "Some" measures the time it takes to use `some()` with a specific function. * "Set" measures the time it takes to use `s.has()` with a specific element. The latest benchmark result shows that: * "Includes" is the fastest approach, followed closely by "Set". * "Some" is the slowest of the three approaches. Keep in mind that these results may vary depending on the specific browser, device platform, and operating system being used.
Related benchmarks:
IndexOf vs Includes
set.has vs. array.includes (string input)
equality vs includes
my own array: indexOf vs includes vs some
Comments
Confirm delete:
Do you really want to delete benchmark?