Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
for vs foreach vs for..in vs for..of, 1m
Compare loop performance with a small load
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/150.0.0.0 Safari/537.36 Edg/150.0.0.0
Browser:
Chrome 150
Operating system:
Windows
Device Platform:
Desktop
Date tested:
28 days ago
for-i
21/s
for-of
21/s
forEach
19/s
for-in
13/s
View exact numbers
Test name
Executions per second
✓
for-i
21 Ops/sec
for-of
21 Ops/sec
forEach
19 Ops/sec
for-in
13 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const array = new Array(1000000); for (let i = 0; i < array.length; i++) { array[i] = Math.random() * 1000; }
Tests:
for-i
for (let i = 0; i < array.length; i++) { const value = array[i]; const str = value.toString(10); }
forEach
array.forEach((value) => { const str = value.toString(10); });
for-in
for (const i in array) { const value = array[i]; const str = value.toString(10); }
for-of
for (const value of array) { const str = value.toString(10); }