Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
for w/length constant vs foreach vs some vs for..of (3)
Compare loop performance
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Browser:
Chrome 118
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
for (lenght 另外儲存)
319884.4 Ops/sec
foreach with operation
108578.1 Ops/sec
some
101570.2 Ops/sec
for..of
332441.1 Ops/sec
for (lenght 不另外儲存)
3663.3 Ops/sec
Script Preparation code:
var array = new Array(10000);
Tests:
for (lenght 另外儲存)
const length = array.length for (var i = 0; i < length; i++) { }
foreach with operation
array.forEach(function(i) { });
some
array.some(function(i) { });
for..of
for (var i of array) { }
for (lenght 不另外儲存)
for (var i = 0; i < array.length; i++) { }