Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
For of vs For vs forEach vs While
(version: 1)
Comparing performance of:
For vs For.. of vs forEach vs While
Created:
one year ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const array = [] let i = 10000 while (i--) { array.push(i) } function whileLoop() { const newArray = [] let i = array.length while (i--) { newArray.push(array[i]) } return newArray } function forLoop() { const newArray = [] for (let i = 0; i < array.length; i++) { newArray.push(array[i]) } return newArray } function forOfLoop() { const newArray = [] for (const item of array) { newArray.push(item) } return newArray } function forEachLoop() { const newArray = [] array.forEach(item => { newArray.push(item) }) }
Tests:
For
forLoop()
For.. of
forOfLoop()
forEach
forEachLoop()
While
whileLoop()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
For
For.. of
forEach
While
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_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Browser/OS:
Chrome 132 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
For
21400.3 Ops/sec
For.. of
23122.0 Ops/sec
forEach
23024.6 Ops/sec
While
22069.1 Ops/sec
Related benchmarks:
for vs foreach vs map vs for..of
for vs for of vs for in
for loops and stuff
loops comparison
ForOf vs Array.Map
Push spread vs forEach vs for of
for-of-foreach
for-of-foreach-1
While vs For of vs For vs forEach
Comments
Confirm delete:
Do you really want to delete benchmark?