Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for vs foreach vs for..in vs for..of, 1m
(version: 1)
Compare loop performance with a small load
Comparing performance of:
for-i vs forEach vs for-in vs for-of
Created:
28 days ago
by:
Registered User
Go to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const array = new Array(1000000); for (let i = 0; i < array.length; i++) { array[i] = Math.random() * 1000; }
Tests:
for-i
for (let i = 0; i < array.length; i++) { const value = array[i]; const str = value.toString(10); }
forEach
array.forEach((value) => { const str = value.toString(10); });
for-in
for (const i in array) { const value = array[i]; const str = value.toString(10); }
for-of
for (const value of array) { const str = value.toString(10); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
for-i
forEach
for-in
for-of
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
28 days ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36 Edg/150.0.0.0
Browser/OS:
Chrome 150 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
for-i
21/s
for-of
21/s
forEach
19/s
for-in
13/s
View exact numbers
Test name
Executions per second
✓
for-i
21 Ops/sec
for-of
21 Ops/sec
forEach
19 Ops/sec
for-in
13 Ops/sec
Related benchmarks
for vs foreach vs for..in vs for..of v2
for vs foreach vs for..in vs for..of zzz2
for vs foreach vs for..in vs for..of zzz3
for vs foreach vs for..in vs for..of (updated)
Comments
Confirm delete:
Do you really want to delete benchmark?