Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Quick sort vs Merge sort
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0
Browser:
Firefox 146
Operating system:
Windows
Device Platform:
Desktop
Date tested:
3 months ago
Test name
Executions per second
Quick Sort
2023.7 Ops/sec
Merge Sort
6316.1 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
var arr = new Array(1000); for (let i = 0; i < size; i++) { arr[i] = Math.floor(Math.random() * 1000000); // Random numbers between 0 and 999999 }
Tests:
Quick Sort
function quickSort(arr) { quick_sort(arr, 0, arr.length - 1); return arr; } function quick_sort(arr, low, high) { if (low < high) { // Get the partition index const pi = partition(arr, low, high); // Recursively sort elements before and after partition quick_sort(arr, low, pi - 1); quick_sort(arr, pi + 1, high); } } function partition(arr, low, high) { // Using last element as pivot const pivot = arr[high]; let i = low - 1; // Index of smaller element for (let j = low; j < high; j++) { // If current element is smaller than or equal to pivot if (arr[j] <= pivot) { i++; // Increment index of smaller element // Swap elements [arr[i], arr[j]] = [arr[j], arr[i]]; } } // Place pivot in its correct position [arr[i + 1], arr[high]] = [arr[high], arr[i + 1]]; return i + 1; } quickSort(arr)
Merge Sort
function mergeSort(arr) { if (arr.length <= 1) return arr; const mid = Math.floor(arr.length / 2); const left = arr.slice(0, mid); const right = arr.slice(mid); return merge(mergeSort(left), mergeSort(right)); } function merge(left, right) { const result = []; let leftIndex = 0; let rightIndex = 0; while (leftIndex < left.length && rightIndex < right.length) { if (left[leftIndex] < right[rightIndex]) { result.push(left[leftIndex]); leftIndex++; } else { result.push(right[rightIndex]); rightIndex++; } } return result.concat(left.slice(leftIndex)).concat(right.slice(rightIndex)); } mergeSort(arr)