Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.includes vs Set.has vas Map.has with large data set
(version: 0)
Comparing performance of:
Array includes vs Set has vs Map has
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = Array(100000).fill().map((i,n)=>n); var b = new Set(a); var c = new Map(a.map(n=>([n,n])));
Tests:
Array includes
return a.includes(9);
Set has
return b.has(9);
Map has
return c.has(9);
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array includes
68758496.0 Ops/sec
Set has
134860896.0 Ops/sec
Map has
130963336.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark definition and test cases. **Benchmark Definition** The benchmark is designed to compare the performance of three different data structures in JavaScript: arrays, sets, and maps. The test case creates a large dataset (100,000 elements) and then uses each of these data structures to search for a specific value (9). The goal is to determine which data structure is most efficient. **Script Preparation Code** The script preparation code generates the large dataset using: 1. `Array(100000).fill().map((i,n)=>n);` - This creates an array with 100,000 elements, where each element is its index in the array. 2. `var b = new Set(a);` - This converts the array to a set, which is a data structure that stores unique values. 3. `var c = new Map(a.map(n=>([n,n])));` - This converts the array to a map, which is an object where each key-value pair has a unique key. **Test Cases** There are three test cases: 1. **Array includes**: Tests if the array contains the value 9 using the `includes()` method. 2. **Set has**: Tests if the set contains the value 9 using the `has()` method. 3. **Map has**: Tests if the map contains the key-value pair (9, 9) using the `has()` method. **Options Compared** The benchmark compares the performance of the following options: * Array search using `includes()` * Set search using `has()` * Map search using `has()` **Pros and Cons of Each Approach** Here's a brief summary of the pros and cons of each approach: 1. **Array includes** * Pros: Widespread support, simple implementation. * Cons: Can be slow for large datasets, may not be optimized for performance in modern browsers. 2. **Set has** * Pros: Fast lookup times, good for unique values. May be faster than array search for large datasets. * Cons: May not be as widely supported as array search, requires creating a set. 3. **Map has** * Pros: Fast lookup times, good for key-value pairs. May be faster than array search for large datasets. * Cons: Requires creating a map, may not be as widely supported as array search. **Library Used** The following libraries are used in the benchmark: 1. `Set` - The built-in JavaScript `Set` object is used to create and manipulate sets. 2. `Map` - The built-in JavaScript `Map` object is used to create and manipulate maps. **Special JS Feature/Syntax** None of the test cases use any special JavaScript features or syntax that are not widely supported. **Other Alternatives** If you're interested in exploring alternative data structures, you might consider: 1. **Linked lists**: A data structure where elements are linked together, which can be faster for insertion and deletion than arrays. 2. **Hash tables**: Data structures that use a hash function to map keys to indices, which can be faster for lookup than sets or maps. Keep in mind that these alternatives may not be as widely supported or optimized as the data structures used in this benchmark.
Related benchmarks:
Array.includes vs Set.has vas Map.has
Array.includes vs Set.has vas Map.has big
Array.includes vs Set.has vas Map retrive
Array.includes vs Set.has vas Map.has 2
Comments
Confirm delete:
Do you really want to delete benchmark?