Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set vs array iteration 100k elements
(version: 0)
Comparing performance of:
array vs set
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = Array.from({ length: 100000 }, (_, i) => i); 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:
11 months 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
Test name
Executions per second
array
23366.3 Ops/sec
set
8012.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested on MeasureThat.net. **Benchmark Definition** The benchmark is called "set vs array iteration 100k elements". The script preparation code is: ```javascript var a = Array.from({ length: 100000 }, (_, i) => i); var b = new Set(a); ``` This code creates an array `a` with 100,000 elements and then converts it to a set `b`. The goal of this benchmark is to compare the performance of iterating over an array versus an object (in this case, a set). **Options Compared** There are two options being compared: 1. **Array Iteration**: The first option iterates over the array using a traditional `for` loop: `for (const x of a) {}` 2. **Set Iteration**: The second option iterates over the set using another `for...of` loop, which is similar to the array iteration but optimized for sets. **Pros and Cons** **Array Iteration** Pros: * Wide support across browsers * Easy to understand and maintain Cons: * Can be slower than other approaches, especially for large datasets * May not utilize modern CPU optimizations **Set Iteration** Pros: * Optimized for sets, which can lead to better performance * Uses modern CPU instructions to iterate over the set Cons: * Less widely supported across browsers (currently only supported in modern versions of Firefox) * Requires a specific syntax and understanding of sets **Other Considerations** When iterating over an array or a set, it's essential to consider the following factors: * **Cache locality**: Accessing elements in a sequence can lead to better cache locality, which can improve performance. * **CPU instructions**: Modern CPUs have optimized instructions for iterating over arrays and sets (e.g., `__builtin_for_each` in Rust). **Library/Feature** There's no specific library or feature being used beyond the built-in `Array.from()` and `Set()` methods. **Special JS Feature/Syntax** The benchmark uses the modern `for...of` loop syntax, which is a relatively new feature introduced in ECMAScript 2015 (ES6). This syntax allows for more concise and expressive iteration over arrays and sets.
Related benchmarks:
set vs array iteration many
set vs array iteration new
set vs array iteration new new
3set vs array iteration New doge333
Comments
Confirm delete:
Do you really want to delete benchmark?