Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
forEach vs for len vs for of
(version: 1)
Comparing performance of:
.forEach vs for..of vs for
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
function generateTestArray() { const testData = []; for (let i = 0; i < 100; ++i) { testData.push({ height: i, width: i * 2, result: 0 }); } return testData; }
Tests:
.forEach
const array = generateTestArray(); array.forEach((item) => { item.result = item.height * item.width; });
for..of
const array = generateTestArray(); for(const item of array) { item.result = item.height * item.width; }
for
const array = generateTestArray(); for (let i = 0; i < array.length; ++i) { array[i].result = array[i].height * array[i].width; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
.forEach
for..of
for
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
.forEach
1555535.2 Ops/sec
for..of
1372322.8 Ops/sec
for
1410736.1 Ops/sec
Related benchmarks:
for vs forEach
for vs forEach (working)
for vs forEach vs for-of
for/for each/forEach
For of VS for VS forEach
For i / For of / ForEach
for vs foreach ej
for-of-foreach
for-of-foreach-1
Comments
Confirm delete:
Do you really want to delete benchmark?