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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser:
Chrome 135
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
raw iteration: forEach
163/s
raw iteration: for..of
122/s
reduce comparision: for..of
96/s
reduce comparision: .reduce
90/s
map comparison: .map
78/s
map comparison: for..of
43/s
View exact numbers
Test name
Executions per second
✓
raw iteration: forEach
163 Ops/sec
raw iteration: for..of
122 Ops/sec
reduce comparision: for..of
96 Ops/sec
reduce comparision: .reduce
90 Ops/sec
map comparison: .map
78 Ops/sec
map comparison: for..of
43 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 => {})