Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Performance of JavaScript .forEach, .map and .reduce vs for and for..of (fork)
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Linux; Android 12; POCO F2 Pro) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.6367.54 Mobile Safari/537.36
Browser:
Chrome Mobile 124
Operating system:
Android
Device Platform:
Mobile
Date tested:
2 years ago
raw iteration: forEach
84/s
raw iteration: for..of
76/s
reduce comparision: for..of
72/s
reduce comparision: .reduce
62/s
map comparison: for..of
24/s
map comparison: .map
16/s
View exact numbers
Test name
Executions per second
✓
raw iteration: forEach
84 Ops/sec
raw iteration: for..of
76 Ops/sec
reduce comparision: for..of
72 Ops/sec
reduce comparision: .reduce
62 Ops/sec
map comparison: for..of
24 Ops/sec
map comparison: .map
16 Ops/sec
Script Preparation code:
function generateTestArray() { const result = []; for (let i = 0; i < 1000000; ++i) { result.push(i); } return result; } window.array = generateTestArray();
Tests:
map comparison: for..of
const r = []; for(const x of array) { r.push(x); }
map comparison: .map
array.map(x => x)
reduce comparision: for..of
let r = 0; for (const x of array) { r += x; }
reduce comparision: .reduce
array.reduce((p, x) => p + x, 0);
raw iteration: for..of
for(const x of array) {}
raw iteration: forEach
array.forEach(x => {})