Is swapping costly or comparison?

I am analysing sorting algorithms, and i have been told that insertion sort works amazing if the number of elements is less than 20.

I considered swapping costly and added some delay there, but it turns out even for less than 20 elements, selection sort is better. Then i made it print number of swaps, and in selection sort they are quite less.

So, is the comparison part that is considered to be costly?
Insertion sort is often implemented without swaps. Insertion sort is very quick if the elements are already sorted or almost sorted and can even beat more advanced algorithms such as Quick sort in such cases.
That would depend on what you are comparing. For built-in types, such as ints, it is not very costly.
You want to use bogosort :D
Topic archived. No new replies allowed.