Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.has vs. array.includes asdfasdfasdf
(version: 0)
Comparing performance of:
includes vs lookup
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
includes
const a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; return a.includes(9)
lookup
const b = new Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) 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
lookup
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
7 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:142.0) Gecko/20100101 Firefox/142.0
Browser/OS:
Firefox 142 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
includes
24797438.0 Ops/sec
lookup
4478196.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into explaining the benchmark and its results. **Benchmark Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided JSON represents two individual test cases: `includes` and `lookup`. Both tests compare the performance of different approaches for checking if an element exists in an array (for `includes`) or a Set object (for `lookup`). In this explanation, we'll focus on the second set of results. **Benchmark Definition** The first benchmark definition is a simple JavaScript code snippet that defines two arrays: `a` and `b`. The code then uses the `includes()` method to check if `9` exists in array `a`, and the `has()` method to check if `9` exists in Set `b`. **Test Cases** There are two test cases: 1. **`includes`**: This test case compares the performance of using the `includes()` method to search for an element in an array. 2. **`lookup`**: This test case compares the performance of using the `has()` method to search for an element in a Set object. **Options Compared** The two options compared are: * Using `includes()` on an array * Using `has()` on a Set object **Pros and Cons of Each Approach:** 1. **`includes()` on an array** * Pros: + Widely supported and well-maintained. + Fast and efficient, especially for large arrays. + Easy to use and understand. * Cons: + Can be slower than using a Set object for small arrays due to the overhead of searching. 2. **`has()` on a Set object** * Pros: + Generally faster than `includes()` for small arrays or sets, as it uses a more efficient data structure. + More memory-efficient, especially for large datasets. * Cons: + Less widely supported and not as well-maintained as `includes()`. + Can be less intuitive to use for developers without experience with Sets. **Library Used** The `Set` object is used in the second test case. A Set is a collection of unique values that can be used to store and look up elements efficiently. It's implemented as an object in JavaScript, which means it provides fast lookup and insertion operations. **Special JS Feature/Syntax** There isn't any specific special feature or syntax mentioned in the benchmark definition or results. **Other Alternatives** If you're looking for alternative approaches to checking if an element exists in an array or Set object, some options include: * Using `indexOf()` on an array (although this is slower than `includes()`) * Implementing a custom binary search algorithm * Using a library like Lodash's `findIndex()` function Keep in mind that the choice of approach depends on your specific use case and performance requirements.
Related benchmarks:
convert to set + set.has vs. array.includes
array.includes vs set.has for small n
array.includes vs. set.has on the fly
Array includes vs Set.has
set.has (w/ creation) vs. array.includes
Comments
Confirm delete:
Do you really want to delete benchmark?