Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Includes (array) vs Has (Set)
(version: 0)
Comparing performance of:
Includes (array) vs Has (Set)
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var a = [1,2,3,4,5,6,7,8,9,10] var b = new Set([1,2,3,4,5,6,7,8,9,10])
Tests:
Includes (array)
a.includes(10)
Has (Set)
b.has(10)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Includes (array)
Has (Set)
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
11 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Browser/OS:
Chrome 137 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Includes (array)
79955112.0 Ops/sec
Has (Set)
181096016.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to explain what's being tested in this benchmark. **What is being compared:** The provided JSON represents a microbenchmark that compares the performance of two different approaches for checking if an element exists in an array versus a set. Specifically, it tests: 1. `includes` method on arrays 2. `has` method on sets **Options being compared:** There are two options being compared: A) Using the `includes` method on arrays (`a.includes(10)`) B) Using the `has` method on sets (`b.has(10)`) **Pros and Cons of each approach:** 1. **Array `includes` method:** * Pros: + Widely supported across different browsers + Easy to implement + Can be faster for small arrays due to caching effects * Cons: + Can be slower for larger arrays because it has to scan the entire array from start to end + May not be as efficient in certain edge cases (e.g., when the array is sparse) 2. **Set `has` method:** * Pros: + Typically faster than the `includes` method, especially for large datasets + More efficient in terms of memory usage because sets only store unique values * Cons: + May not be supported across all browsers (notably older versions) + Requires creating a set object before using it **Library and purpose:** In this benchmark, the `Set` library is used to create a set data structure. A set in JavaScript is an unordered collection of unique values. The `has` method on sets returns a boolean value indicating whether an element exists in the set. **Special JS feature or syntax:** There is no special JavaScript feature or syntax being tested in this benchmark. It only uses standard JavaScript methods and data structures (arrays and sets). **Other alternatives:** If you're looking for alternative approaches to check if an element exists in an array or set, here are a few options: * For arrays: + Using `some()` method with a callback function + Using `indexOf()` method (although it may return -1 if the element is not found) * For sets: + Using `size` property to check if an element exists in the set (although this might be slower than using the `has` method) Keep in mind that these alternatives might have different performance characteristics and may not always be as efficient or widely supported as the methods being compared in this benchmark.
Related benchmarks:
convert to set + set.has vs. array.includes
set.has vs. array.includes v22
array.includes vs. set.has on the fly
set.has (w/ creation) vs. array.includes
Comments
Confirm delete:
Do you really want to delete benchmark?