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);
    }
  • filter with a map

     
    arr.filter(item => item.assigned).map(item => item.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
    filter with a map

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 months ago)
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36
Chrome Mobile 131 on Android
View result in a separate tab
Test name Executions per second
flatMap 3408.4 Ops/sec
reduce with push 10756.0 Ops/sec
loop with push 10914.1 Ops/sec
filter with a map 5866.6 Ops/sec