Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.has vs. array.includes (with big array)
(version: 0)
Comparing performance of:
includes vs lookup
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11]; var b = new Set(a)
Tests:
includes
return a.includes(9)
lookup
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:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
includes
97288144.0 Ops/sec
lookup
153256480.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and test cases to understand what is being tested. **Benchmark Definition** The benchmark definition consists of two test cases: 1. `return a.includes(9)` 2. `return b.has(9)` Both tests are comparing the performance of different approaches for checking if an element exists in an array or a Set data structure. **Set and Array Data Structure** * A Set is a collection of unique values, which allows for fast lookups using the `has` method. * An array is a contiguous block of memory that stores a sequence of elements. **Test Cases** The two test cases are: 1. **`includes`**: This test case measures the performance of checking if an element exists in an array using the `includes` method. 2. **`lookup`**: This test case measures the performance of checking if an element exists in a Set data structure using the `has` method. **Library and Purpose** The library used is JavaScript's built-in `Set` and `Array` data structures. The purpose of these libraries is to provide efficient data structures for storing and manipulating collections of unique values or sequences of elements, respectively. **Special JS Feature/Syntax** None mentioned in the provided benchmark definition. **Pros and Cons of Different Approaches** Here are some pros and cons of each approach: 1. **`includes` method (array)**: * Pros: widely supported, easy to use. * Cons: may have slower performance compared to `has` method for large arrays. 2. **`has` method (Set)**: * Pros: fast lookups, unique elements. * Cons: requires a Set data structure, which can be slower than an array for very large datasets. **Other Alternatives** If the available JavaScript implementation does not support the `Set` data structure or if it's not suitable for performance-critical applications, alternative data structures like hash tables or binary search trees could be used instead. Overall, this benchmark measures the performance of two different approaches for checking if an element exists in a collection: one using the `includes` method on an array and another using the `has` method on a Set.
Related benchmarks:
set.has vs. array.includes 3
set.has vs. array.includes bigger sample
set.has vs. array.includes (with big array and last index match)
set.has vs. array.includes (300 elements)
Comments
Confirm delete:
Do you really want to delete benchmark?