sorting test (v3)

Revision 3 of this benchmark created on


Preparation HTML

<script>
function generateTasks(numTasks ) {
  const priorities = ['high', 'medium', 'low'];
  const tasks= [];

  for (let i = 0; i < numTasks; i++) {
    const randomPriority = priorities[Math.floor(Math.random() * priorities.length)];
    tasks.push({
      id: i + 1,
      name: `Task ${i + 1}`,
      priority: randomPriority,
    });
  }

  return tasks;
}

// Generate a large dataset
const largeTaskDataset = generateTasks(10);
</script>

Setup


Test runner

Ready to run.

Testing in
TestOps/sec
bubble sort
// Test Case 1: Bubble Sort
function bubbleSort(tasks) {
  const priorityOrder = { high: 1, medium: 2, low: 3 };

  for (let i = 0; i < tasks.length; i++) {
    for (let j = 0; j < tasks.length - 1 - i; j++) {
      const task1 = tasks[j];
      const task2 = tasks[j + 1];

      if (priorityOrder[task1.priority] > priorityOrder[task2.priority]) {
        [tasks[j], tasks[j + 1]] = [tasks[j + 1], tasks[j]];
      }
    }
  }

  return tasks;
}
const bubbleSortResult = bubbleSort([...largeTaskDataset]);
ready
quick sort
function quickSort(tasks) {
  const priorityOrder = { high: 1, medium: 2, low: 3 };

  return tasks.sort((task1, task2) => {
    if (!task1.priority || !task2.priority) {
      console.error("Task priority is missing");
    }
    return priorityOrder[task1.priority] - priorityOrder[task2.priority];
  });
}
const quickSortResult = quickSort([...largeTaskDataset]);
ready

Revisions

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