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
Test name
Executions per second
For
547.7 Ops/sec
For (with function call)
515.7 Ops/sec
For Each (function)
1331068.6 Ops/sec
For Each (trivial lambda)
1326592.9 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))