Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set vs Includes
(version: 0)
Comparing performance of:
Array includes vs Set
Created:
8 years ago
by:
Guest
Jump to the latest result
Tests:
Array includes
array = [] for (var i = 0; i <= 10000; i++) { array[i] = i } array2 = array.reverse().filter((e, i, a) => !(a.slice(i+1).includes(e))).reverse()
Set
array = [] for (var i = 0; i <= 10000; i++) { array[i] = i } array2 = Array.from(new Set(array))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array includes
Set
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested, compared, and other considerations. **Benchmark Overview** The benchmark compares two approaches to filter an array: using `includes()` method (also known as "array includes") versus using a `Set` data structure. The test cases are designed to measure which approach is faster for large arrays. **Options Compared** Two options are being compared: 1. **Array Includes**: Using the `includes()` method to check if an element exists in the array. 2. **Set**: Using a `Set` data structure to filter out elements from the original array. **Pros and Cons of Each Approach:** ### Array Includes Pros: * Familiar syntax for most developers * Easy to understand and implement * Fast lookup times, but can be slower for large arrays due to unnecessary computations Cons: * Can lead to unnecessary computations (e.g., creating intermediate arrays or performing multiple lookups) * May not be optimized by the browser's JavaScript engine ### Set Pros: * Efficient data structure for fast lookup and insertion times * Eliminates unnecessary computations compared to array includes * Can be faster for large arrays due to its optimized implementation Cons: * Requires a `Set` object creation, which can introduce overhead * May not be as familiar or intuitive for some developers **Library Used:** None explicitly mentioned in the benchmark definition. However, it's worth noting that `Array.from(new Set(array))` is using the `Set` constructor to create a new set from the original array. **Special JS Feature/Syntax:** * None explicitly mentioned in the provided code snippets. * However, `var i = 0; i <= 10000; i++` uses an older syntax for looping (`for (var i = 0; i <= 10000; i++)`) compared to modern ES6/ES7 syntax (`for (let i = 0; i <= 10000; i++)`). This may not be relevant to the benchmark's performance, but it's worth noting for clarity. **Alternative Approaches:** Other approaches that could potentially be used for this benchmark include: * Using `filter()` method on the original array * Using a custom implementation with loop and conditional statements * Utilizing browser-specific features like WebAssembly or SIMD instructions (not applicable in this case) In conclusion, the benchmark is testing two different approaches to filter an array: using the `includes()` method versus creating a `Set` data structure. The test aims to measure which approach is faster for large arrays and provide insights into the performance characteristics of each method. **Benchmark Preparation Code Explanation** The provided "Script Preparation Code" and "Html Preparation Code" fields are empty, suggesting that no additional setup or configuration is required for this benchmark.
Related benchmarks:
convert to set + set.has vs. array.includes
new Set([x]).has vs [x].includes
array.includes vs. set.has on the fly
set.has (w/ creation) vs. array.includes
equals vs includes (one value)
Comments
Confirm delete:
Do you really want to delete benchmark?