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), [])
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    flatMap
    reduce with push

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 5 days ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Chrome 135 on Windows
View result in a separate tab
Test name Executions per second
flatMap 4886.7 Ops/sec
reduce with push 14433.4 Ops/sec