Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.includes vs Set.has vas Map.has big
(version: 0)
Comparing performance of:
Array includes vs Set has vs Map has
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = [...Array(10000).keys()]; var b = new Set([...Array(10000).keys()]); var c = new Map([...Array(10000).keys()].map((i) => [i, i]));
Tests:
Array includes
return a.includes(5673);
Set has
return b.has(5673);
Map has
return c.has(5673);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Array includes
Set has
Map has
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser/OS:
Chrome 124 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array includes
22921128.0 Ops/sec
Set has
27927760.0 Ops/sec
Map has
25914896.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
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: 1. `a`: An array of 10,000 integers created using `[...Array(10000).keys()]`. 2. `b`: A Set of 10,000 unique integers created by converting the same array to a Set. 3. `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: 1. **Array.includes**: This method searches for a value in an array using the `includes()` method. 2. **Set.has**: This method checks if a value exists in a Set using the `has()` method. 3. **Map.has**: This method retrieves the value associated with a key from a Map using the `has()` method. **Pros and Cons** 1. **Array.includes**: * Pros: Simple to implement, widely supported across browsers. * Cons: May be slower for large datasets due to the need to iterate over each element. 2. **Set.has**: * Pros: Fast and efficient for finding unique values in a dataset. * Cons: Requires creating a Set, which may incur additional overhead for smaller datasets. 3. **Map.has**: * Pros: Can be faster than `Array.includes` for large datasets due to the Map's data structure optimizations. * Cons: Less widely supported across browsers and requires creating a Map. **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: * Dataset size * Number of unique values * Browser support **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.
Related benchmarks:
Array.includes vs Set.has vas Map.has
Array.includes vs Set.has vas Map retrive
Array.includes vs Set.has vas Map.has 2
Array.includes vs Set.has vas Map.has with large data set
Comments
Confirm delete:
Do you really want to delete benchmark?