Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.has vs. array.includes performance
(version: 0)
Comparing performance of:
includes vs lookup
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
includes
var a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; return a.includes(9)
lookup
var a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; var b = new Set(a) 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:
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 provided JSON and explain what's being tested. **Benchmark Definition** The provided JSON defines a benchmark with two individual test cases: `includes` and `lookup`. The benchmark is comparing the performance of two different approaches to check if an element exists in an array or a Set data structure. **Test Cases** 1. **includes**: This test case uses the `array.includes()` method to search for the presence of a specific element (in this case, 9) within the array. 2. **lookup**: This test case uses a `Set` object created from the same array and checks if the element (9) exists using the `has()` method. **Options Compared** Two different approaches are being compared: * **array.includes()**: A widely used method for checking element presence in arrays. * **Set.has()**: A method provided by the Set data structure, which is a specialized collection of unique values. **Pros and Cons** 1. **array.includes()**: * Pros: Wide browser support, easy to use, and often implemented as an O(1) operation (on average). * Cons: Can be slower for very large arrays due to the need to iterate over the entire array. 2. **Set.has()**: * Pros: Faster performance, especially for large datasets, since Set operations are typically optimized for insertion and lookup. * Cons: Requires creating a Set object from the original array, which may incur additional overhead. **Libraries and Special Features** None of the test cases use external libraries or special JavaScript features beyond what's available in modern browsers. However, note that some older browsers might not support the `Set` data structure or `includes()` method. **Other Alternatives** If you're looking for alternative approaches to check element presence in an array, consider using: * **Array.prototype.indexOf()**: Similar to `array.includes()`, but returns the index of the first occurrence (or -1 if not found). * **indexOf() method on specific arrays**: Some libraries or frameworks might provide optimized versions of this method. In summary, the provided benchmark compares two approaches for checking element presence in an array: `array.includes()` and `Set.has()`. The choice between these methods depends on performance considerations, as `Set.has()` is generally faster but requires creating a Set object from the original array.
Related benchmarks:
convert to set + set.has vs. array.includes
Includes (array) vs Has (Set)
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?