Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
javascript loops bissssss
(version: 1)
Comparing performance of:
foreach vs for-in vs for-of vs for vs optimized-for
Created:
25 days ago
by:
Guest
Go 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:
2 days ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36 Edg/151.0.0.0
Browser/OS:
Chrome 151 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
optimized-for
12/s
for
12/s
foreach
11/s
for-of
10/s
for-in
9/s
View exact numbers
Test name
Executions per second
✓
optimized-for
12 Ops/sec
for
12 Ops/sec
foreach
11 Ops/sec
for-of
10 Ops/sec
for-in
9 Ops/sec
Comments
Confirm delete:
Do you really want to delete benchmark?