Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.includes vs Set.has vas Map retrive
(version: 0)
Comparing performance of:
Array includes vs Set has vs map retrive data 789456123230
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; var b = new Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); var c = new Map([[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]);
Tests:
Array includes
return a.includes(9);
Set has
return b.has(9);
map retrive data 789456123230
return c[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 retrive data 789456123230
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array includes
31449826.0 Ops/sec
Set has
31802740.0 Ops/sec
map retrive data 789456123230
28716176.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its various components. **Benchmark Overview** The provided benchmark tests three different approaches to retrieve an element from a sequence: `Array.includes()`, `Set.has()`, and `Map.get()` for a Map with a fixed key. The goal is to compare their performance, efficiency, and consistency across different browsers and devices. **Options Compared** 1. **Array.includes()**: This method checks if a specific value exists in an array. 2. **Set.has()**: This method checks if a specific value exists in a Set data structure. 3. **Map.get()**: This method retrieves the value associated with a given key from a Map. **Pros and Cons of Each Approach** 1. **Array.includes()**: * Pros: Widely supported, easy to use, and suitable for arrays containing unique elements. * Cons: Can be slower than Set.has() and Map.get() for large datasets, as it iterates through the array. 2. **Set.has()**: * Pros: Faster than Array.includes() for large datasets, as Sets use hash tables for efficient lookups. * Cons: May not be suitable for arrays containing duplicate elements, as Sets only store unique values. 3. **Map.get()**: * Pros: Fast and efficient for looking up keys in a Map, especially when the key is known beforehand. * Cons: Requires knowing the exact key to retrieve a value, which might not always be possible. **Library Usage** None of the provided benchmark cases use any external libraries. The script preparation code only involves creating arrays, sets, and maps using native JavaScript constructors. **Special JS Features/Syntax** There are no special JavaScript features or syntax used in this benchmark that would require additional explanation. **Other Alternatives** If you're looking for alternative approaches to retrieve elements from sequences, consider the following: * **Array.indexOf()**: Similar to Array.includes(), but returns the index of the first occurrence instead of a boolean value. * **Set.size**: Returns the number of unique elements in a Set. * **Map.keys() / Map.values() / Map.entries()**: Iterate over keys, values, or key-value pairs in a Map. Keep in mind that these alternatives might have different performance characteristics and use cases compared to the methods tested in this benchmark.
Related benchmarks:
Array.includes vs Set.has vas Map.has
Array.includes vs Set.has vs Map.has vs Object in
Array.includes vs Set.has vas Map.has vs Object accessor
Array.includes vs Set.has vas Map.has 2
Comments
Confirm delete:
Do you really want to delete benchmark?