Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for...of with empty array and set
(version: 0)
Comparing performance of:
for...of empty array vs for...of empty set
Created:
2 years ago
by:
Registered User
Jump to the latest result
Tests:
for...of empty array
const array = []; for(let i = 0; i < 100000; i ++) { for(const something of array) {} }
for...of empty set
const set = new Set(); for(let i = 0; i < 100000; i ++) { for(const something of set) {} }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
for...of empty array
for...of empty set
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
for...of empty array
39956.2 Ops/sec
for...of empty set
4957.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of MeasureThat.net and explore what's being tested in this benchmark. **Benchmark Definition** The benchmark definition is a JSON object that provides metadata about the test case. In this case, it contains two test cases: * "for...of with empty array and set" * No description or preparation code is provided for either test case. This suggests that the benchmark is designed to measure the performance of `for...of` loops in JavaScript when iterating over empty arrays and sets. **Options Compared** The two options being compared are: 1. **Empty Array**: The first test case iterates over an empty array using a traditional `for` loop with an index variable (`i`). This approach uses the array's length as a bound to iterate. 2. **Empty Set**: The second test case iterates over an empty set using a traditional `for...of` loop without a bound. In JavaScript, sets are iterable collections of unique values. **Pros and Cons** 1. **Traditional `for` Loop with Index Variable (Empty Array)**: * Pros: This approach is likely to be more familiar and efficient for developers who are used to traditional iteration methods. * Cons: This approach requires manual bounds checking, which can lead to unnecessary iterations if the array length changes. 2. **Traditional `for...of` Loop without Bound (Empty Set)**: * Pros: This approach takes advantage of the set's built-in iterator protocol, eliminating the need for manual bounds checking. * Cons: Some older browsers might not support this syntax or have limited performance optimizations. **Library and Purpose** None are explicitly mentioned in the benchmark definition. However, both `Set` objects and arrays are native JavaScript data structures that provide iterative capabilities. **Special JS Feature or Syntax** The benchmark utilizes the `for...of` loop syntax, which is a relatively modern feature introduced in ECMAScript 2015 (ES6). This loop construct allows iterating over iterable collections without needing explicit bounds checking. **Other Alternatives** If you want to compare these benchmarks with alternative approaches, consider the following: 1. **Traditional `for` Loop with Array Length**: Iterate using a traditional `for` loop and access array length as a bound. 2. **Using `forEach()` Method**: Use the `forEach()` method on arrays or sets instead of traditional loops. 3. **Arrow Functions**: Compare the performance of arrow functions (`() => { ... }`) versus traditional function expressions for iteration. Keep in mind that these alternatives might change the benchmark's behavior, so you should verify their results to ensure they align with your expectations.
Related benchmarks:
set vs array includes
Create Set vs loop
fastest way to convert set to array
set vs array iteration 100k elements
new set vs array includes
Comments
Confirm delete:
Do you really want to delete benchmark?