HASTY
JS
performance
Bubble sort VS. Selection sort
A performance test where we run Bubble sort against Selection sort.
Click the run button to get the performance of "bubble"- and "selection"-sorting algorithms.
Globals
const data = [ ...new Array(250).fill(0).map(Math.random) ]
Cases
0 ops/s
function bubbleSort(arr) { const len = arr.length; for (let i = len - 1; i >= 0; i--) { for (let j = 1; j <= i; j++) { if (arr[j - 1] > arr[j]) { const temp = arr[j - 1]; arr[j - 1] = arr[j]; arr[j] = temp; } } } return arr; } bubbleSort(data);
0 ops/s
function selectionSort(arr) { const len = arr.length; let minIdx; let temp; for (let i = 0; i < len; i++) { minIdx = i; for (let j = i + 1; j < len; j++) { if (arr[j] < arr[minIdx]) { minIdx = j; } } temp = arr[i]; arr[i] = arr[minIdx]; arr[minIdx] = temp; } return arr; } selectionSort(data);
Shorts
Wall of Love
Embed
Share
Donate
Options
Epochs:
Timeout:
Run