Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array entries: For Of, For Loop, .forEach
(version: 0)
Comparing performance of:
For Of Entries loop vs Standard For Loop vs For Each Functional
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
window.data = Array(50000).fill(0).map(() => String(Math.random()));
Tests:
For Of Entries loop
let name = 'start'; for (const [index, value] of window.data.entries()) name = value + index;
Standard For Loop
let name = 'start'; for (let i = 0, d = window.data; i < d.length; ++i) name = d[i] + i;
For Each Functional
let name = 'start'; window.data.forEach((value, i) => name = value + i);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
For Of Entries loop
Standard For Loop
For Each Functional
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 benchmark and analyze what is being tested. **Benchmark Overview** The benchmark compares three different approaches to iterate over an array in JavaScript: 1. **"For Of Entries loop"`**: Uses the `for...of` loop syntax, which was introduced in ECMAScript 2015 (ES6) as a way to iterate over iterable objects. 2. **"Standard For Loop"`**: Uses a traditional `for` loop with an index variable (`i`) and array length (`d.length`). 3. **"For Each Functional"`**: Uses the `forEach()` method, which is a part of the Array prototype. **Library and Purpose** None of these approaches rely on external libraries. They are all built-in JavaScript features. **Special JS Feature or Syntax** The "For Of Entries loop" uses the `for...of` loop syntax, which is a new way to iterate over arrays introduced in ES6. **Options Compared** Each test case compares the execution performance of one specific iteration method against others. This allows users to see which approach is faster for each type of iteration. Here are some pros and cons of each approach: * **For Of Entries loop**: Pros - concise, readable code; Cons - may not be supported in older browsers or versions of JavaScript. * **Standard For Loop**: Pros - widely supported across different browsers and versions of JavaScript; Cons - can be verbose, less readable than the other two options. * **For Each Functional (forEach())**: Pros - concise, easy to read; Cons - may be slower than the traditional for loop in some cases. **Other Considerations** The benchmark also considers device platform, operating system, and browser version, which can affect performance. The results are likely weighted by these factors to provide a more accurate representation of real-world performance. In terms of alternatives, other ways to iterate over arrays include: * Using `Array.prototype.forEach()` * Using `Array.prototype.map()` or `Array.prototype.filter()`, depending on the use case * Using custom iteration functions (e.g., `forEach()`, `reduce()`) * Using external libraries like Lodash However, these alternatives are not explicitly included in this benchmark, and the focus is on comparing the native JavaScript iteration methods.
Related benchmarks:
Fill array with random integers
array vs int32Array
array vs int16array
Object vs Map lookup: random integer key
Map and Object number key vs string key
Comments
Confirm delete:
Do you really want to delete benchmark?