Script Preparation code:
AخA
 
var raw = new Array(250).fill({
    id: 'gid://something/Something/something',
    handle: 'something',
    name: 'Something',
    categories: ['SOMETHING'],
    lastViewedAt: '2022-03-18T21:30:18Z',
    isPinned: false,
});
Tests:
  • flatMap

    x
     
    const flatMapped = raw.flatMap(({ id, categories, handle, name, lastViewedAt, isPinned }) => {
      if (categories.length === 0) {
        return [];
      }
      return {
        category: categories[0],
        handle,
        url: "https://google.com/",
        name,
        lastViewedAt: lastViewedAt == null ? null : new Date(lastViewedAt),
        author: "someone",
        isPinned,
        type: "something",
        gid: id,
      };
    });
  • reduce

     
    const reduced = raw.reduce(function (array, { id, categories, handle, name, lastViewedAt, isPinned }) {
      if (categories.length === 0) {
        return array;
      }
      array.push({
        category: categories[0],
        handle,
        url: "https://google.com/",
        name,
        lastViewedAt: lastViewedAt == null ? null : new Date(lastViewedAt),
        author: "someone",
        isPinned,
        type: "something",
        gid: id,
      });
      return array;
    }, []);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    flatMap
    reduce

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0
Firefox 102 on Windows
View result in a separate tab
Test name Executions per second
flatMap 15177.9 Ops/sec
reduce 17209.0 Ops/sec