agents map and sort (v3)

Revision 3 of this benchmark created on


Setup

const agentsListArr = new Array(10000).fill({
	id: Math.round(Math.random() * 10000),
	    projectId: "test-project-id",
    category: "test-category",
    description: "test-description",
    id: "test-id",
    group: "Test Group",
    name: "Test Agent",
    thumbnail: "test-thumbnail.jpg"
})

const favouriteAgents = {
	data: [{ id: 10 }, { id: 12}, { id: 50 }]
}

const agentsObject = agentsListArr.reduce((acc, agent) => {
  acc[agent.id] = agent;
  return acc;
}, {});

Test runner

Ready to run.

Testing in
TestOps/sec
expensive
const agentsList = Object.values(agentsObject)

  const sortedAgents = agentsList
    .map((agent) => {
      const favourited = favouriteAgents.data.some((favouriteAgent) => favouriteAgent.id === agent.id);

      return {
        ...agent,
        favourited,
      };
    })
    .sort((a, b) => {
      if (a.favourited && !b.favourited) return -1;
      if (b.favourited && !a.favourited) return 1;

      return 0;
    });
ready
null
const x = 1;
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.