Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
javascript loops (bigger loops)
(version: 1)
Comparing performance of:
foreach vs for-in vs for-of vs for vs optimized-for
Created:
one year ago
by:
Guest
Jump to the latest result
Tests:
foreach
const items = Array.from({length: 1000000}, () => Math.floor(Math.random() * 40)); let index = 0; items.forEach(i => index++);
for-in
const items = Array.from({length: 1000000}, () => Math.floor(Math.random() * 40)); let index = 0; for (let i in items) { index++; }
for-of
const items = Array.from({length: 1000000}, () => Math.floor(Math.random() * 40)); let index = 0; for (let i of items) { index++; }
for
const items = Array.from({length: 1000000}, () => Math.floor(Math.random() * 40)); let index = 0; for(let i = 0; i < items.length; ++i) { index++; }
optimized-for
const items = Array.from({length: 1000000}, () => Math.floor(Math.random() * 40)); let index = 0; for(let i = items.length; i > 0; --i) { index++; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
foreach
for-in
for-of
for
optimized-for
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:131.0) Gecko/20100101 Firefox/131.0
Browser/OS:
Firefox 131 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
foreach
68.6 Ops/sec
for-in
27.8 Ops/sec
for-of
77.6 Ops/sec
for
93.9 Ops/sec
optimized-for
94.4 Ops/sec
Related benchmarks:
javascript loops
Array Entries vs fori
javascript rulettaa
javascript ruletz
javascript loops small
javascript loops (foreach, for-in, for-of, for, map, reduce) 1000 items
javascript loops with reduce 3
javascript loops with reduce 4
javascript loops with reduce 5
Comments
Confirm delete:
Do you really want to delete benchmark?