Concat N sorted list and sort the list

Benchmark created on


Setup

const startDate = new Date('2024-10-01T00:00:00Z');
const endDate = new Date('2024-10-31T00:00:00Z');

function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

function getSortedMovementList(n) {
  const list = [];

  for (let i = 0; i < n; i++) {
    list.push({
      title: 'Pago de servicio',
      description: 'Netflix',
      amount: getRandomInt(1, 1000),
      currency_id: 1,
      date: new Date(getRandomInt(startDate.getTime(), endDate.getTime())),
      href: '/banking/balance/movements/B1RKFRFOT/detail',
    });
  }

  list.sort((a, b) => b.date.getTime() - a.date.getTime());

  return list;
}

const sorted200 = {
  list1: getSortedMovementList(200),
  list2: getSortedMovementList(200),
  list3: getSortedMovementList(200),
}

const sorted450 = {
  list1: getSortedMovementList(450),
  list2: getSortedMovementList(450),
  list3: getSortedMovementList(450),
}

const sorted900 = {
  list1: getSortedMovementList(900),
  list2: getSortedMovementList(900),
  list3: getSortedMovementList(900),
}

const sorted1800 = {
  list1: getSortedMovementList(1800),
  list2: getSortedMovementList(1800),
  list3: getSortedMovementList(1800),
}

const sorted2500 = {
  list1: getSortedMovementList(2500),
  list2: getSortedMovementList(2500),
  list3: getSortedMovementList(2500),
}

const sorted5000 = {
  list1: getSortedMovementList(5000),
  list2: getSortedMovementList(5000),
  list3: getSortedMovementList(5000),
}

const sorted10000 = {
  list1: getSortedMovementList(10000),
  list2: getSortedMovementList(10000),
  list3: getSortedMovementList(10000),
}

Test runner

Ready to run.

Testing in
TestOps/sec
Sort 200 items per list
const mergedList = sorted200.list1.concat(sorted200.list2, sorted200.list3);
mergedList.sort((a, b) => b.date.getTime() - a.date.getTime());
ready
Sort 450 items per list
const mergedList = sorted450.list1.concat(sorted450.list2, sorted450.list3);
mergedList.sort((a, b) => b.date.getTime() - a.date.getTime());
ready
Sort 900 items per list
const mergedList = sorted900.list1.concat(sorted900.list2, sorted900.list3);
mergedList.sort((a, b) => b.date.getTime() - a.date.getTime());
ready
Sort 1800 items per list
const mergedList = sorted1800.list1.concat(sorted1800.list2, sorted1800.list3);
mergedList.sort((a, b) => b.date.getTime() - a.date.getTime());
ready
Sort 2500 items per list
const mergedList = sorted2500.list1.concat(sorted2500.list2, sorted2500.list3);
mergedList.sort((a, b) => b.date.getTime() - a.date.getTime());
ready
Sort 5000 items per list
const mergedList = sorted5000.list1.concat(sorted5000.list2, sorted5000.list3);
mergedList.sort((a, b) => b.date.getTime() - a.date.getTime());
ready
Sort 10000 items per list
const mergedList = sorted10000.list1.concat(sorted10000.list2, sorted10000.list3);
mergedList.sort((a, b) => b.date.getTime() - a.date.getTime());
ready

Revisions

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