Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Performance of JavaScript .forEach() vs for()
(version: 1)
Comparing performance of:
.forEach vs .for (init array)
Created:
7 months ago
by:
Guest
Jump to the latest result
Script Preparation code:
function generateTestArray() { const result = []; for (let i = 0; i < 1000000; ++i) { result.push({ a: i, b: i / 2, r: 0, }); } return result; }
Tests:
.forEach
const array = generateTestArray(); array.forEach((x) => { x.r = x.a + x.b; });
.for (init array)
const array = generateTestArray(); const r = new Array(array.length); for (let i = 0; i < array.length; ++i) { r[i] = array[i].a + array[i].b; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
.forEach
.for (init array)
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
7 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0
Browser/OS:
Firefox 128 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
.forEach
18.6 Ops/sec
.for (init array)
19.9 Ops/sec
Related benchmarks:
Performance of JavaScript .forEach, .map and .reduce vs for and for..of
Performance of JavaScript .forEach, .map and .reduce vs for and for..ofdasdadadasd ca2qdd
Performance of JavaScript .forEach, .map and .reduce vs for and for..ofCXCcccc
for vs foreach ej
Performance of JavaScript .forEach, .map and .reduce vs for and for..of2
for-of-foreach
Performance of JavaScript .forEach, .map and .reduce vs for and for..of with 1000p
Performance of JavaScript .forEach vs for..of
Performance of JavaScript .forEach, .map and .reduce vs for and for..of 2232132
Comments
Confirm delete:
Do you really want to delete benchmark?