Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Printing 1000 array elements, for vs for (with function call) vs foreach
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser:
Chrome 134
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
For Each (function)
1.3M/s
For Each (trivial lambda)
1.3M/s
For
548/s
For (with function call)
516/s
View exact numbers
Test name
Executions per second
✓
For Each (function)
1,331,069 Ops/sec
For Each (trivial lambda)
1,326,593 Ops/sec
For
548 Ops/sec
For (with function call)
516 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
var array = new Array(1000); let count = 1000; function print(i) { console.log(array[i]); }
Tests:
For
for (var i = 0; i < count; i++) { console.log(array[i]); }
For (with function call)
for (var i = 0; i < count; i++) { print(i); }
For Each (function)
array.forEach(print)
For Each (trivial lambda)
array.forEach((i) => print(i))