Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.includes vs Set.has vas Map.has 2
(version: 0)
Comparing performance of:
Array includes vs Set has
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = new Array(1000).fill(null).map((_, index) => index); var b = new Set(Array.from(a));
Tests:
Array includes
return a.includes(9);
Set has
return b.has(9);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array includes
Set has
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Android 14; Mobile; rv:132.0) Gecko/132.0 Firefox/132.0
Browser/OS:
Firefox Mobile 132 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array includes
8877871.0 Ops/sec
Set has
863853312.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark and explain what's being tested, compared, and the pros and cons of each approach. **Benchmark Definition** The benchmark is designed to compare the performance of three different data structures in JavaScript: `Array.includes`, `Set.has`, and `Map.has`. The script preparation code creates two arrays (`a` and `b`) with 1000 elements each. One array is converted to a set, which is then used to create another variable `b`. **Options Compared** The three options being compared are: 1. **Array.includes**: A method that checks if an element exists in the array. 2. **Set.has**: A method that checks if an element exists in the set. 3. **Map.has**: A method that checks if a key exists in the map. **Pros and Cons of Each Approach** Here's a brief overview of each approach: 1. **Array.includes** * Pros: Widely supported, easy to use, and fast for large arrays. * Cons: May have performance issues for very large arrays due to its iterative nature. 2. **Set.has** * Pros: Fast lookup times, especially when dealing with unique values or sets of unique values. Sets are also more memory-efficient than arrays. * Cons: Not designed for sequential access or random element selection. Requires converting an array to a set before using this method. 3. **Map.has** * Pros: Similar performance characteristics to `Set.has`, but with the added benefit of key-value pairs and efficient lookup times. * Cons: Requires creating a map object, which may have overhead compared to arrays or sets. **Library Usage** In this benchmark, no specific libraries are used beyond what's built into JavaScript. However, it's worth noting that some versions of Chrome (like Chrome 120) use the `Map.has` method under the hood due to its performance benefits for hash-based operations. **Special JS Features/Syntax** There doesn't appear to be any special or experimental JavaScript features/syntax used in this benchmark. The focus is on comparing three well-established methods. **Alternative Approaches** If you were to create an alternative benchmark, you could consider adding other data structures or algorithms, such as: * **Array.includes alternatives**: Implementing a more efficient algorithm for finding elements in large arrays, like using `bitwise operations`. * **Set and Map optimizations**: Investigating ways to optimize set and map lookups further, such as using caching or pre-computation of hash values. * **Multi-threaded testing**: Using multiple threads or processes to test the performance of each method across different CPU architectures. Keep in mind that benchmarks like MeasureThat.net often focus on a specific problem domain (in this case, lookup operations) and may not cover all possible scenarios.
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 with large data set
Comments
Confirm delete:
Do you really want to delete benchmark?