Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.has vs. array.includes large 1
(version: 0)
Comparing performance of:
includes vs lookup
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = []; for(let i = 0; i < 10000; i++){ a.push(i); } var b = new Set(a)
Tests:
includes
return a.includes(5000)
lookup
return b.has(5000)
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:
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 definition and individual test cases to understand what's being tested. **Benchmark Definition JSON:** The provided benchmark is called "set.has vs. array.includes large 1". This benchmark compares the performance of two approaches: 1. `array.includes` (or simply "includes") 2. `Set.has` These two methods are used to check if a specific value exists in an array or set, respectively. **Options Compared:** * `array.includes`: checks if a specific value (`5000`) exists in the array `a`. * `Set.has`: checks if a specific value (`5000`) exists in the set `b`, which is created from the array `a`. **Pros and Cons of Each Approach:** 1. `array.includes`: * Pros: widely supported, simple to implement. * Cons: O(n) time complexity, which can be slow for large datasets. 2. `Set.has`: * Pros: O(1) average time complexity on modern browsers (thanks to hash tables), suitable for large datasets. * Cons: requires a Set object, may not be supported in older browsers. **Library Used:** In this benchmark, the library used is not explicitly mentioned, but it's likely that the browser being tested (e.g., Chrome) provides built-in support for Set objects. The `Set` constructor is used to create a set from an array (`a`). **Special JS Feature or Syntax:** None are mentioned in this benchmark. **Other Considerations:** * The benchmark creates a large array `a` with 10,000 elements and then converts it to a set `b`. This ensures that the test is not just measuring the performance of `Set.has` but also compares it to `array.includes` on large datasets. * The test measures executions per second (EPS), which indicates how many times each method can be executed in one second. A higher EPS value generally means better performance. **Alternatives:** Other alternatives for checking if a value exists in an array or set include: * Using `find()` with a callback function: `array.find(value => value === 5000)` (O(n) time complexity) * Using `every()` and verifying that the condition is met for all elements: `array.every(element => element === 5000)` (O(n) time complexity) * Using a custom implementation, such as using a binary search algorithm. However, it's worth noting that these alternatives may not be as efficient or widely supported as `Set.has` on modern browsers.
Related benchmarks:
set.has vs. array.includes large
set.has vs. array.includes (1 million entries)
set.has vs. array.includes - large array
set vs array iteration 100k elements
Comments
Confirm delete:
Do you really want to delete benchmark?