Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
for w/length constant vs foreach vs some vs for..of (2)
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/120.0.0.0 Safari/537.36
Browser:
Chrome 120
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
foreach with operation
4.1M/s
some
4.1M/s
for (lenght 另外儲存)
275K/s
for..of
240K/s
for (lenght 不另外儲存)
148K/s
View exact numbers
Test name
Executions per second
✓
foreach with operation
4,144,534 Ops/sec
some
4,103,745 Ops/sec
for (lenght 另外儲存)
274,789 Ops/sec
for..of
240,023 Ops/sec
for (lenght 不另外儲存)
148,498 Ops/sec
Script Preparation code:
var array = new Array(100);
Tests:
for (lenght 另外儲存)
const length = array.length for (var i = 0; i < length; i++) { array[i]; }
foreach with operation
array.forEach(function(i) { array[i]; });
some
array.some(function(i) { array[i]; });
for..of
for (var i of array) { array[i]; }
for (lenght 不另外儲存)
for (var i = 0; i < array.length; i++) { array[i]; }