Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
quicksort
(version: 0)
Comparing performance of:
t1 vs t2
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var items = [5,3,7,6,2,9,63, 95, 63, 26, 76, 19, 65, 8, 63, 26];
Tests:
t1
function swap(items, leftIndex, rightIndex){ var temp = items[leftIndex]; items[leftIndex] = items[rightIndex]; items[rightIndex] = temp; } function partition(items, left, right) { var pivot = items[Math.floor((right + left) / 2)], //middle element i = left, //left pointer j = right; //right pointer while (i <= j) { while (items[i] < pivot) { i++; } while (items[j] > pivot) { j--; } if (i <= j) { swap(items, i, j); //sawpping two elements i++; j--; } } return i; } function quickSort(items, left, right) { var index; if (items.length > 1) { index = partition(items, left, right); //index returned from partition if (left < index - 1) { //more elements on the left side of the pivot quickSort(items, left, index - 1); } if (index < right) { //more elements on the right side of the pivot quickSort(items, index, right); } } return items; } console.log(quickSort(items, 0, items.length - 1));
t2
function quickSortBasic(array) { if(array.length < 2) { return array; } var pivot = array[0]; var lesserArray = []; var greaterArray = []; for (var i = 1; i < array.length; i++) { if ( array[i] > pivot ) { greaterArray.push(array[i]); } else { lesserArray.push(array[i]); } } return quickSortBasic(lesserArray).concat(pivot, quickSortBasic(greaterArray)); } console.log(quickSortBasic(items, 0, items.length - 1));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
t1
t2
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
Array Sorting Methods
Sorting speed comparison
Quick Sort
Sort method comparisons (quicksort, for loop, Arra.prototype.sort)
Javascript Sorting Algorithms 2
Comments
Confirm delete:
Do you really want to delete benchmark?