HASTY
JS
performance
Bubble sort VS. Insertion sort
A performance test where we run Bubble sort against Insertion sort.
Click the run button to get the performance of "bubble"- and "insertion"-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 insertionSort(arr) { const n = arr.length; for (let i = 1; i < n; i++) { const current = arr[i]; let j = i - 1; while (j > -1 && current < arr[j]) { arr[j + 1] = arr[j]; j--; } arr[j + 1] = current; } return arr; } insertionSort(data);
Shorts
Wall of Love
Embed
Share
Donate
Options
Epochs:
Timeout:
Run