Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
forEach vs for len vs for of
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
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:
Chrome 131
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
.forEach
1555535.2 Ops/sec
for..of
1372322.8 Ops/sec
for
1410736.1 Ops/sec
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; }