var a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
return a.includes(9)
var b = new Set(a)
return b.has(9)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
includes | |
lookup |
Test name | Executions per second |
---|---|
includes | 19585232.0 Ops/sec |
lookup | 2178414.8 Ops/sec |
Let's break down the benchmark and explain what's being tested, compared, and their pros and cons.
Benchmark Name: set.has vs. array.includes (run new Set in has test)
This benchmark compares two approaches for checking if an element exists in a JavaScript array: using the includes()
method on the array itself, and creating a new Set
instance from the array and then using the has()
method on the set.
Options Compared:
includes()
method: This approach checks if a specific value is present in the array by iterating through its elements.has()
method to check for the presence of an element.Pros and Cons:
includes()
method:Other Considerations:
includes()
method.Set
as its underlying data structure (e.g., using Array.from()
and Set
) might provide better performance and scalability.Library:
None of the benchmark tests explicitly use any external libraries. However, creating a new Set instance involves the internal Set
class in JavaScript.
Special JS Feature or Syntax:
This benchmark uses standard JavaScript features and syntax without any special or experimental features.
Now, let's look at the individual test cases:
includes
:includes()
method.lookup
:has()
method to check for the presence of an element.The latest benchmark result shows that Chrome 96 outperforms itself when running the lookup
test, while still performing slower than itself when running the includes
test. This may indicate that there are issues with the execution or measurement of this specific benchmark case.