agents map and sort

Benchmark created on


Setup

const agentsList = new Array(1000).fill({
	id: Math.round(Math.random() * 100),
	    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 }]
}

Test runner

Ready to run.

Testing in
TestOps/sec
expensive
  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.