TL;DR
A set of microbenchmarks run on Chrome 143 (V8) found for-of loops can perform on par with a classic for loop that caches array length in many cases. For very large arrays the results were more variable, but additional warmup narrowed the gap.
What happened
The author ran sequential loop benchmarks on Chrome 143 (Windows 11, AMD Ryzen 5000U) using jsbenchmark.com and later jsben.ch to compare six loop styles over five array types. Arrays of integers, floats, strings, objects and mixed values were generated at three sizes: 5,000; 50,000; and 500,000 elements. Loop variants tested were classic for with i++, classic for with cached length, reverse for with i–, for-of, for-in, and Array.prototype.forEach. Each loop called a no-op function to avoid trivial optimization. At N=5,000 the cached-length classic for and for-of were the fastest; at N=50,000 the pattern held but forEach degraded proportionally; at N=500,000 for-of performed worse in initial runs (especially on floats) but improved with repeated runs and heavy warmup (200 and 1,500 repeats). For-in was consistently the slowest, and the cached-length classic for was the most consistently fast across tests.
Why it matters
- Modern JS engines (V8) perform aggressive optimizations that can make higher-level constructs like for-of competitive with indexed loops.
- Developers should not assume for-of is always markedly slower; in many practical cases it can match a well-written classic loop.
- For performance-sensitive code operating on very large arrays, warmup and environment-specific benchmarking remain important because optimizations can be less reliable.
- Code ergonomics still favor for-of for readability when microsecond-level differences are not critical.
Key facts
- Environment used: Chrome 143 running V8 on Windows 11 with an AMD Ryzen 5000U CPU.
- Five array element types tested: integers, floats, strings, objects and mixed values.
- Array sizes used: N = 5,000; 50,000; 500,000.
- Six loop styles compared: classic for (i++), classic for with cached length, reverse for (i–), for-of, for-in, and forEach.
- Each loop invoked a dummy function per element to reduce trivial engine optimizations.
- At N=5,000 the fastest were cached-length classic for and for-of, with classic i++ and forEach slightly behind.
- At N=50,000 the pattern remained but forEach became relatively slower; for-in worsened further.
- At N=500,000 for-of initially lagged (notably on floats) but came close to cached-length performance after repeated warmup runs (200 and 1,500 repeats).
- forEach showed limited benefit from warmup; for-in was consistently the slowest.
- Author's conclusion: cached-length classic for is the most consistent winner; for-of can be as fast but is trickier on huge arrays.
What to watch next
- How future V8 (and other engine) optimizations change relative loop performance — engine behavior can evolve quickly.
- Performance of for-of vs. classic loops on different browsers and hardware — results here are for Chrome 143 on one CPU.
- For code that must be fast on very large datasets, validate performance with targeted benchmarks in your deployment environment.
Quick glossary
- for-of loop: A JavaScript loop construct that iterates over iterable objects using the language's iteration protocol, yielding each value directly.
- Iteration protocol: A JavaScript convention where an iterator exposes a next() method that returns an object with value and done properties to control iteration.
- V8: Google's open-source JavaScript engine used in Chrome and Node.js that applies runtime and ahead-of-time optimizations.
- Cached array length: A pattern where an array's length is read into a local variable before a loop to avoid repeated property access during iteration.
- forEach: An Array.prototype method that executes a provided function once for each array element, with higher-level overhead than simple indexed loops.
Reader FAQ
Are for-of loops always as fast as classic indexed loops?
Not always; the benchmark shows for-of can match cached-length classic for in many cases, but results vary on very large arrays and depend on engine optimizations.
Which loop was the most consistent winner in the tests?
The classic for loop that caches the array length was the most consistent top performer across the tested cases.
Did the benchmarks include multiple browsers or engines?
No — tests reported were run on Chrome 143 (V8) only; multiple browsers were not confirmed in the source.
Does forEach benefit from warmup runs?
In these tests forEach showed little improvement from warmup compared with for-of and cached-length for loops.

JavaScript's for-of loops are actually fast Published on 01/01/2026 Updated on 04/01/2026 #ecmascript #javascript #benchmark When it comes to iterating over arrays, for…of loops are believed to be significantly slower…
Sources
- JavaScript's For-Of Loops Are Fast
- Why is for…of loop so much slower than the traditional for …
- Measuring Performance of Different JavaScript Loop Types
- Benchmarking 'for', 'while', 'for…of', and 'Array.forEach'
Related posts
- Show HN: Replaced Beads with tk – a faster, Markdown-based task tracker
- OSS Sustain Guard: Signals and metrics for open-source dependency health
- Local-first: Why the Term Defies a Clean Definition and Needs Nuance