Script Preparation code:
AخA
 
var arr = Array.from({length:10000}, (v, i) => ({name: i, assigned: Math.random() < 0.5}));
Tests:
  • flatMap

     
    arr.flatMap((o) => (o.assigned ? [o.name] : []));
  • reduce with push

     
    arr.reduce((a, o) => (o.assigned && a.push(o.name), a), [])
  • loop with push

     
    {
      const a = [];
      for (const o of arr) if (o.assigned) a.push(o.name);
    }
  • Filtermap

     
    arr.filter(o => o.assigned).map(o => o.name)
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    flatMap
    reduce with push
    loop with push
    Filtermap

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
Chrome 119 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
flatMap 2404.1 Ops/sec
reduce with push 22659.1 Ops/sec
loop with push 30287.9 Ops/sec
Filtermap 20122.3 Ops/sec