Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
for vs foreach vs some
Compare loop performance
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0
Browser:
Firefox 140
Operating system:
Linux
Device Platform:
Desktop
Date tested:
8 months ago
Benchmark engine:
Benchmark.js
some
992.3M/s
while
29.6M/s
for
16.4M/s
for with predefined size
16.0M/s
foreach
9.4M/s
for..in
437K/s
View exact numbers
Test name
Executions per second
✓
some
992,253,568 Ops/sec
while
29,638,222 Ops/sec
for
16,443,280 Ops/sec
for with predefined size
16,030,622 Ops/sec
foreach
9,379,542 Ops/sec
for..in
436,621 Ops/sec
Script Preparation code:
var array = new Array(100); for(var i = 0; i < array.length; i++) { array[i] = Math.random(); }
Tests:
for..in
for (var i in array) { array[i]; }
foreach
array.forEach(function(item, index) { return item; });
some
array.some(function(item, index) { return item === array[index]; });
for
for (var i = 0; i < array.length; i++) { array[i]; }
for with predefined size
var size = array.length for (var i = 0; i < size; i++) { array[i]; }
while
while((a=array.pop()) !== undefined){ //do your stuff }