Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.includes vs Set.has vas Map.has vs Object accessor
(version: 0)
Comparing performance of:
Array includes vs Set has vs Map has vs Object accessor
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]]); var d = {a: 1, b: 2, c: 3, d: 4, e: 5, f:6, g:7, h:8, i:9, l:10};
Tests:
Array includes
return a.includes(9);
Set has
return b.has(9);
Map has
return c.has(9);
Object accessor
return d[i]
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Array includes
Set has
Map has
Object accessor
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1.1 Mobile/15E148 Safari/604.1
Browser/OS:
Mobile Safari 18 on iOS 18.1.1
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array includes
90838304.0 Ops/sec
Set has
463124704.0 Ops/sec
Map has
463449248.0 Ops/sec
Object accessor
249505792.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **What is being tested?** The test measures the performance of four different approaches to check if a value exists in an array or a collection: 1. `Array.includes()` 2. `Set.has()` 3. `Map.has()` 4. Object accessor (`d[i]`) These methods are used to determine whether a specific value is present in the respective data structures. **Options compared** The benchmark compares the performance of each method across different execution scenarios: * `Array.includes()` vs `Set.has()` vs `Map.has()`: These three methods are tested with an array and a set/object, respectively. * Object accessor (`d[i]`): This method is tested alone, using an object with a dynamic key. **Pros and Cons of each approach** Here's a brief overview of the advantages and disadvantages of each method: 1. **Array.includes()** * Pros: Simple, widely supported, and easy to implement. * Cons: May be slower for large arrays due to the iteration process. 2. **Set.has()** * Pros: Fast lookups using hash tables, suitable for large datasets. * Cons: Requires a Set object, which may not be available in all environments. 3. **Map.has()** * Pros: Similar to Set.has(), with fast lookups and suitable for large datasets. * Cons: May require additional overhead due to the Map object's implementation. 4. **Object accessor (`d[i]`)**: * Pros: Simple, lightweight, and easy to implement. * Cons: May be slower due to the dynamic lookup process. **Library and purpose** In the test case "Array includes", `Set.has()` is used, which implies that a Set object is available. However, in the provided benchmark result, it's noted that both `Set.has()` and `Map.has()` have similar performance characteristics. This suggests that the Set and Map objects might be implemented similarly or with identical performance characteristics. **Special JS features or syntax** None are mentioned explicitly in the provided benchmark definition or results.
Related benchmarks:
Array.includes vs Set.has vas Map.has
Includes (array) vs Has (Map)
Array.includes vs Set.has vs Map.has vs Object in
Array.includes vs Set.has vas Map retrive
Comments
Confirm delete:
Do you really want to delete benchmark?