var a = [];
for(let i = 0; i < 1000; i++){
a.push(i);
}
var b = new Set(a)
return a.includes(500)
return b.has(500)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
includes | |
lookup |
Test name | Executions per second |
---|---|
includes | 11180123.0 Ops/sec |
lookup | 11449933.0 Ops/sec |
Let's break down the provided benchmark and its test cases.
Benchmark Description
The benchmark compares two approaches: set.has
(also known as "lookup" in the benchmark) and array.includes
. These two methods are used to check if an element exists within a set or an array, respectively.
What is tested?
In this specific benchmark:
a
) of 1000 elements is created using a loop.b
) is created from the array a
.set.has(500)
).array.includes(500)
).Comparison of Options
The benchmark compares two options:
set.has
(also known as "lookup"): This method is used to check if a value exists within a Set object. In JavaScript, a Set is an unordered collection of unique values.array.includes
: This method is used to check if a value exists within an array. In JavaScript, arrays are ordered collections of elements that can have duplicate values.indexOf()
, filter()
, map()
, etc., making them more versatile than sets for specific use cases.Library/Functionality Used
The benchmark uses two built-in JavaScript libraries:
includes()
are utilized for checking if an element exists within the array.Special JS Features/Syntax
There are no specific JavaScript features or syntax used in this benchmark, other than built-in libraries and functions like Set and Array.