Was your application a profile and that turned out to be a bottleneck? Or are you trying to overestimate?
Bubblesort can also work very well. In particular, when your data is already sorted, this is actually optimal and will beat any merging tutorial or sorting heap. If you do not give complete restrictions (the cost of replacing elements, the requirements for stability, in place or not), no one can fully answer this question.
In any case, for the four elements itβs pretty obvious how to implement an efficient merge sort.
For odd (inferior 2) sizes, I find reverse insertion sorting to be a general optimization. Take a look at the Javas collation implementation. I believe that it already has such a small array optimization. Have you verified that the sorting procedure that you would call no longer performs such optimizations?
source share