Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
for vs foreach vs map vs for..of
Compare loop performance
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:141.0) Gecko/20100101 Firefox/141.0
Browser:
Firefox 141
Operating system:
Windows
Device Platform:
Desktop
Date tested:
9 months ago
Test name
Executions per second
for
863397.4 Ops/sec
foreach
299900.2 Ops/sec
some
365526.2 Ops/sec
for..of
315006.6 Ops/sec
Script Preparation code:
var array = new Array(1000).fill(1);
Tests:
for
const result = []; for (var i = 0; i < array.length; i++) { result.push(array[i] * 2); }
foreach
const result = []; array.forEach(function(i) { result.push(i * 2); });
some
const result = array.map(function(i) { return i * 2; });
for..of
const result = []; for (var i of array) { result.push(i * 2); }