Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
While vs For of vs For vs forEach
(version: 1)
Comparing performance of:
While vs For vs For.. of vs forEach
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:
While
whileLoop()
For
forLoop()
For.. of
forOfLoop()
forEach
forEachLoop()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
While
For
For.. of
forEach
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
While
21237.7 Ops/sec
For
22434.3 Ops/sec
For.. of
22590.1 Ops/sec
forEach
22511.7 Ops/sec
Related benchmarks:
for vs for of vs for in
js array perfomance
for loops and stuff
Iteration test
loops comparison
ForOf vs Array.Map
for-of-foreach
for-of-foreach-1
For of vs For vs forEach vs While
Comments
Confirm delete:
Do you really want to delete benchmark?