Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
array sort
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36
Browser:
Chrome 116
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
built in sort
5780.2 Ops/sec
custom sort
27979.7 Ops/sec
Script Preparation code:
var input = []; for (var i = 0; i < 1000; i++) { input[i] = Math.round(Math.random() * 1000000); }
Tests:
built in sort
input.slice(0).sort(function(a, b) { return a - b; });
custom sort
function fast_quicksort(ary) { var stack = []; var entry = [0, ary.length, 2 * Math.floor(Math.log(ary.length) / Math.log(2))]; stack.push(entry); while (stack.length > 0) { entry = stack.pop(); var start = entry[0]; var end = entry[1]; var depth = entry[2]; if (depth == 0) { ary = shell_sort_bound(ary, start, end); continue; } depth--; var pivot = Math.round((start + end) / 2); var pivotNewIndex = inplace_quicksort_partition(ary, start, end, pivot); if (end - pivotNewIndex > 16) { entry = [pivotNewIndex, end, depth]; stack.push(entry); } if (pivotNewIndex - start > 16) { entry = [start, pivotNewIndex, depth]; stack.push(entry); } } ary = insertion_sort(ary); return ary; } function shell_sort_bound(ary, start, end) { var inc = Math.round((start + end) / 2), i, j, t; while (inc >= start) { for (i = inc; i < end; i++) { t = ary[i]; j = i; while (j >= inc && ary[j - inc] > t) { ary[j] = ary[j - inc]; j -= inc; } ary[j] = t; } inc = Math.round(inc / 2.2); } return ary; } function inplace_quicksort_partition(ary, start, end, pivotIndex) { var i = start, j = end; var pivot = ary[pivotIndex]; while(true) { while(ary[i] < pivot) {i++}; j--; while(pivot < ary[j]) {j--}; if(!(i<j)) { return i; } swap(ary,i,j); i++; } } function insertion_sort(ary) { for(var i=1,l=ary.length;i<l;i++) { var value = ary[i]; for(var j=i - 1;j>=0;j--) { if(ary[j] <= value) break; ary[j+1] = ary[j]; } ary[j+1] = value; } return ary; } function swap(ary, a, b) { var t = ary[a]; ary[a] = ary[b]; ary[b] = t; } fast_quicksort(input.slice(0));