Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Performance of JavaScript .reduce vs. for vs. for..of
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/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
for
161457120.0 Ops/sec
.reduce
126695832.0 Ops/sec
.reduce (destructuring)
125649416.0 Ops/sec
for..of (reduce)
170421568.0 Ops/sec
for..of (reduce) (destructuring)
169179584.0 Ops/sec
Script Preparation code:
const array = []; for (let i = 0; i < 1000000; ++i) { result.push({ a: i, b: i / 2, }); }
Tests:
for
const r = 0; for (let i = 0; i < array.length; ++i) { r += array[i].a + array[i].b; }
.reduce
array.reduce((p, x) => p + x.a + x.b, 0);
.reduce (destructuring)
array.reduce((p, {a,b}) => p + a + b, 0);
for..of (reduce)
let r = 0; for (const x of array) { r += x.a + x.b; }
for..of (reduce) (destructuring)
let r = 0; for (const {a,b} of array) { r += a + b; }