Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set vs array iteration new new
(version: 0)
Comparing performance of:
array vs set
Created:
2 years ago
by:
Guest
Go to the latest result
Script Preparation code:
var a = Array(100000).fill(1); var b = new Set(a)
Tests:
array
for (const x of a) {}
set
for (const x of b) {}
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
array
set
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 137 on Android
View result in a separate tab
Embed
Embed Benchmark Result
set
89.1M/s
array
23K/s
View exact numbers
Test name
Executions per second
✓
set
89,053,872 Ops/sec
array
23,391 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. **Benchmark Overview** The benchmark is designed to compare the performance of two approaches: iterating over an array using a `for...of` loop, and iterating over a Set data structure (created from the array) using a `for...of` loop. The test script prepares an array and a set with 100,000 elements each. **Options Compared** The benchmark is comparing two options: 1. **Array iteration**: Iterating over the original array using a `for...of` loop. 2. **Set iteration**: Iterating over the Set data structure created from the array using a `for...of` loop. **Pros and Cons of Each Approach** * **Array Iteration**: + Pros: This approach is likely to be more familiar and intuitive for developers, as it's a traditional way of iterating over arrays. + Cons: For large datasets, iterating over an array can lead to slower performance due to the need to access and traverse each element individually. * **Set Iteration**: + Pros: Sets are optimized for fast lookups and iteration, making this approach potentially faster for large datasets. + Cons: This approach may be less familiar or intuitive for developers who aren't familiar with Set data structures. **Library and Purpose** In the provided benchmark script, a library is not explicitly used. However, the `Set` data structure is being used, which is a built-in JavaScript data structure that provides fast lookup, insertion, and deletion operations. **Special JS Feature or Syntax (None in this case)** There are no special JavaScript features or syntaxes used in this benchmark script. **Other Alternatives** If you were to modify the benchmark or create new benchmarks, you might consider adding other alternatives or variations, such as: * Using `for` loops instead of `for...of` loops * Iterating over a linked list (if implementing from scratch) * Using a custom data structure like a trie or suffix tree Keep in mind that these alternative approaches would require additional script modifications to accommodate the changes. **Benchmark Preparation Code Explanation** The provided Script Preparation Code creates an array with 100,000 elements and fills it with values using `Array(100000).fill(1)`. It then creates a Set from this array using `new Set(a)`, where `a` is the reference to the array. This Set is used as input for both iteration tests. **Individual Test Cases** The benchmark has two test cases: * "array": Iterates over the original array using a `for...of` loop. * "set": Iterates over the Set data structure created from the array using a `for...of` loop. These test cases are likely to provide insight into the performance differences between iterating over arrays and sets.
Related benchmarks
set vs array iteration 100k elements
set vs array iteration new
3set vs array iteration New doge333
Comments
Confirm delete:
Do you really want to delete benchmark?