Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
loop options performance
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/125.0.0.0 Safari/537.36
Browser:
Chrome 125
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
flatMap
208.2 Ops/sec
reduce
427.8 Ops/sec
for of loop
935.5 Ops/sec
filter and map
295.7 Ops/sec
forEach
826.5 Ops/sec
Script Preparation code:
var arr = Array.from({length:100000}, (v, i) => ({name: i, shouldNotBeFiltered: i % 2 === 0}));
Tests:
flatMap
arr.flatMap(({ name, shouldNotBeFiltered }) => (shouldNotBeFiltered ? [name] : []));
reduce
arr.reduce((acc, { name, shouldNotBeFiltered }) => { if (shouldNotBeFiltered) { const elementToPush = name; acc.push(elementToPush); } return acc; }, []);
for of loop
const result = []; for (const { name, shouldNotBeFiltered } of arr) { if (shouldNotBeFiltered) { const elementToPush = name; result.push(elementToPush); } }
filter and map
arr.filter(({ shouldNotBeFiltered }) => shouldNotBeFiltered).map(({ name }) => name);
forEach
const result = []; arr.forEach(({ name, shouldNotBeFiltered }) => { if (shouldNotBeFiltered) { const elementToPush = name; result.push(elementToPush); } });