var arr = [];
var i = 0;
while (i <= 1E5) arr.push(++i);
var set = new Set(arr);
const isExits = arr.includes(1E5)
const isExits = set.has(1E5)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Array.prototype.includes | |
Set.prototype.has |
Test name | Executions per second |
---|---|
Array.prototype.includes | 26261336.0 Ops/sec |
Set.prototype.has | 27952500.0 Ops/sec |
Let's break down the provided benchmark JSON and explain what's being tested.
Benchmark Definition
The benchmark is defined by two separate script preparation codes, which are:
arr
with 100,000 elements using a while loop and pushes each element to the array.set
created from the arr
array.Options being compared
The benchmark is comparing two different data structures in JavaScript: Arrays (Array.prototype.includes
) and Sets (Set.prototype.has
). Both methods are used to check if an element (in this case, 100,000) exists within the collection.
Pros and Cons of each approach
Array.prototype.includes
):Set.prototype.has
):Library usage
In this benchmark, no external libraries are used. However, it's worth noting that in real-world scenarios, you might use libraries like Lodash for utility functions or other libraries for data structures if you're working with complex datasets.
Special JS feature or syntax
There is no special JavaScript feature or syntax being used here, as the benchmark focuses on comparing two standard methods (includes
and has
) between Arrays and Sets.