Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
for vs for...of vs .map vs .forEach
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0
Browser:
Chrome 144
Operating system:
Windows
Device Platform:
Desktop
Date tested:
3 months ago
Test name
Executions per second
for with init array
403.5 Ops/sec
for with init length and array
392.2 Ops/sec
for ... of
184.8 Ops/sec
.map
101.2 Ops/sec
.forEach
96.4 Ops/sec
Script Preparation code:
function generateTestArray() { const result = []; for (let i = 0; i < 1000000; ++i) { result.push(i); } return result; }
Tests:
for with init array
const array = generateTestArray(); const output = new Array(array.length); for (let i = 0; i < array.length; ++i) { output[i] = array[i]; }
for with init length and array
const array = generateTestArray(); const length = array.length; const output = new Array(length); for (let i = 0; i < length; ++i) { output[i] = array[i]; }
for ... of
const array = generateTestArray(); const output = []; for (const x of array) { output.push(x); }
.map
const array = generateTestArray(); const output = array.map(x => x);
.forEach
const array = generateTestArray(); const output = []; array.forEach(x => output.push(x));