Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
While vs For of vs For vs forEach
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
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:
Chrome 132
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
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
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()