var a = [Array(10000).keys()];
var b = new Set([Array(10000).keys()]);
var c = new Map([Array(10000).keys()].map((i) => [i, i]));
return a.includes(5673);
return b.has(5673);
return c.has(5673);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Array includes | |
Set has | |
Map has |
Test name | Executions per second |
---|---|
Array includes | 22921128.0 Ops/sec |
Set has | 27927760.0 Ops/sec |
Map has | 25914896.0 Ops/sec |
Let's break down the benchmark and explain what's being tested, the options compared, their pros and cons, and other considerations.
Benchmark Definition
The benchmark is designed to compare the performance of three different methods: Array.includes
, Set.has
, and Map.has
. The method being tested is the one that performs an operation on a large dataset (a
, b
, or c
) when searching for a specific value (in this case, 5673).
Script Preparation Code
The script preparation code creates three datasets:
a
: An array of 10,000 integers created using [...Array(10000).keys()]
.b
: A Set of 10,000 unique integers created by converting the same array to a Set.c
: A Map with the same key-value pairs as the previous dataset.These datasets are used for each test case.
Options Compared
The three options being compared are:
includes()
method.has()
method.has()
method.Pros and Cons
Array.includes
for large datasets due to the Map's data structure optimizations.Other Considerations
The test cases are designed to measure the performance of each method in different scenarios. The results will provide insights into which method performs best under various conditions, such as:
Library Usage (Set and Map)
In this benchmark, Set and Map are used as data structures to store large datasets. These libraries are built-in to JavaScript and provide efficient ways to work with collections.
Special JS Feature/Syntax
None mentioned in the provided information.