Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array includes vs Set.has
(version: 0)
Comparing performance of:
includes vs Set.has
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];
Tests:
includes
return a.includes(9);
Set.has
var b = new Set(a); return b.has(9);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
includes
Set.has
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 16_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Mobile/15E148 Safari/604.1
Browser/OS:
Mobile Safari 16 on iOS 16.1.1
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
includes
10899384.0 Ops/sec
Set.has
1941320.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what is being tested on the MeasureThat.net website. **Benchmark Definition** The benchmark definition is a JSON object that contains information about the test case being run. In this case, it defines two test cases: 1. `Array includes vs Set.has` 2. Two individual test cases: * `includes`: Tests if an array (`a`) contains a specific element (9) using the `includes` method. * `Set.has`: Tests if a set (`b`) created from the same array (`a`) contains the same element (9) using the `has` method of sets. **Options being compared** In this benchmark, two options are being compared: 1. **Array includes**: Using the `includes` method on an array to check for membership. 2. **Set has**: Using a Set data structure to store unique elements and checking if that set contains a specific element using the `has` method. **Pros and Cons of each approach** Here's a brief overview of the pros and cons of each approach: 1. **Array includes** * Pros: + Lightweight and easy to implement. + Fast lookup times in modern browsers. * Cons: + Can be slower for very large arrays due to the overhead of iterating over elements. + May not be as efficient as sets for unique element storage. 2. **Set has** * Pros: + More efficient than arrays for storing and looking up unique elements. + Fast lookup times on average (O(1) time complexity). * Cons: + Requires the creation of a new Set object, which can be slower than just using `includes`. + May not be suitable for all use cases, as Sets are designed to store unique values and may not preserve order. **Library and its purpose** In this benchmark, no external libraries are used. However, it's worth noting that the `Set` data structure is a native JavaScript feature that was introduced in ECMAScript 2015 (ES6). **Special JS features or syntax** There are no special JS features or syntax mentioned in the benchmark definition or individual test cases. **Other alternatives** If you needed to compare other approaches, some alternative options could be: * Using `indexOf` instead of `includes` * Using `Array.prototype.findIndex` instead of `includes` * Comparing performance using different data structures, such as linked lists or trees * Examining the performance of different algorithms for finding elements in an array (e.g., binary search) These alternatives would likely require additional modifications to the benchmark definition and individual test cases.
Related benchmarks:
convert to set + set.has vs. array.includes
set vs array
Includes (array) vs Has (Set)
array.includes vs. set.has on the fly
Comments
Confirm delete:
Do you really want to delete benchmark?