Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
javascript loops (foreach, for-in, for-of, for, map, reduce) 1000 items
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:128.0) Gecko/20100101 Firefox/128.0
Browser:
Firefox 128
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
foreach
79092.3 Ops/sec
for-in
13608.0 Ops/sec
for-of
85048.9 Ops/sec
for
107709.6 Ops/sec
optimized-for
107767.8 Ops/sec
map
79024.6 Ops/sec
reduce
71843.7 Ops/sec
Tests:
foreach
const items = Array.from({length: 1000}, () => Math.floor(Math.random() * 40)); let index = 0; items.forEach(i => index++);
for-in
const items = Array.from({length: 1000}, () => Math.floor(Math.random() * 40)); let index = 0; for (let i in items) { index++; }
for-of
const items = Array.from({length: 1000}, () => Math.floor(Math.random() * 40)); let index = 0; for (let i of items) { index++; }
for
const items = Array.from({length: 1000}, () => Math.floor(Math.random() * 40)); let index = 0; for(let i = 0; i < items.length; ++i) { index++; }
optimized-for
const items = Array.from({length: 1000}, () => Math.floor(Math.random() * 40)); let index = 0; for(let i = items.length; i > 0; --i) { index++; }
map
const items = Array.from({length: 1000}, () => Math.floor(Math.random() * 40)); items.map((_, i)=> i++);
reduce
const items = Array.from({length: 1000}, () => Math.floor(Math.random() * 40)); items.reduce((acc, curr)=> acc++, 0);