Insertion sort VS. Selection sort
A performance test where we run Insertion sort against Selection sort.
Click the run button to get the performance of "insertion"- and "selection"-sorting algorithms.
Globals
const data = [ ...new Array(250).fill(0).map(Math.random) ]
Cases
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);
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);
Embed
Share
Options
Epochs:
Timeout:
Run
H
ASTY.DEV
JS
performance
Pre-defined
Notebooks
Blog
Donate
Wall of love 😻
Telegram
Mastodon
Twitter
Use HASTY
Try demo