<p>The other answers are interesting and fairly good, but I believe that I can provide some additional elements of answer, point per point:</p>

<ul>
<li>Is it worth the effort? Well, if you need to sort small collections of integers and the sorting networks are tuned to take advantage of some instructions as much as possible, it might be worth the effort. The following graph presents the results of sorting a million arrays of <code>int</code> of size 0-14 with different sorting algorithms. As you can see, the sorting networks can provide a significant speedup if you really need it.</li>
</ul>

<p><img src="https://camo.githubusercontent.com/474b4e969d8043f0b8d83b073ff77bcd032b916a/68747470733a2f2f692e696d6775722e636f6d2f476152486e39782e706e67" alt=""></p>

<ul>
<li><p>No standard implementation of <code>std::sort</code> I know of use sorting networks; when they are not fine-tuned, they might be slower than a straight insertion sort. libc++'s <code>std::sort</code> has dedicated algorithms to sort 0 thru 5 values at once but they it doesn't use sorting networks either. The only sorting algorithm I know of which uses sorting networks to sort a few values is <a href="https://github.com/BonzaiThePenguin/WikiSort" rel="noreferrer">Wikisort</a>. That said, the research paper <a href="http://arxiv.org/abs/1505.01962" rel="noreferrer"><em>Applying Sorting Networks to Synthesize Optimized Sorting Libraries</em></a> suggests that sorting networks could be used to sort small arrays or to improve recursive sorting algorithms such as quicksort, but only if they are fine-tuned to take advantage of specific hardware instructions.</p>

<p>The <a href="https://github.com/khegeman/floki" rel="noreferrer">access aligned sort</a> algorithm is some kind of bottom-up mergesort that apparently uses bitonic sorting networks implemented with SIMD instructions for the first pass. Apparently, the algorithm could be faster than the standard library one for some scalar types.</p></li>
<li><p>I can actually provide such information for the simple reason that I developed <a href="https://github.com/Morwenn/cpp-sort" rel="noreferrer">a C++14 sorting library</a> that happens to provide efficient sorting networks of size 0 thru 32 that implement the optimizations described in the previous section. I used it to generate the graph in the first section. I am still working on the sorting networks part of the library to provide size-optimal, depth-optimal and swaps-optimal networks. Small optimal sorting networks are found with brute force while bigger sorting networks use results from the litterature.</p>

<p>Note that none of the sorting algorithms in the library directly use sorting networks, but you can adapt them so that a sorting network will be picked whenever the sorting algorithm is given a small <code>std::array</code> or a small fixed-size C array:</p>

<pre><code>using namespace cppsort;

// Sorters are function objects that can be
// adapted with sorter adapters from the
// library
using sorter = small_array_adapter&lt;
    std_sorter,
    sorting_network_sorter
&gt;;

// Now you can use it as a function
sorter sort;

// Instead of a size-agnostic sorting algorithm,
// sort will use an optimal sorting network for
// 5 inputs since the bound of the array can be
// deduced at compile time
int arr[] = { 2, 4, 7, 9, 3 };
sort(arr);
</code></pre>

<p>As mentioned above, the library provides efficient sorting networks for built-in integers, but you're probably out of luck if you need to sort small arrays of something else (<em>e.g.</em> my latest benchmarks show that they are not better than a straight insertion sort even for <code>long long int</code>).</p></li>
<li><p>You could probably use template metaprogramming to generate sorting networks of any size, but no known algorithm can generate the best sorting networks, so you might as well write the best ones by hand. I don't think the ones generated by simple algorithms can actually provide usable and efficient networks anyway (Batcher's odd-even sort and pairwise sorting networks might be the only usable ones) <em>[Another answer seems to show that generated networks could actually work]</em>.</p></li>
</ul>
Very fast sorting of fixed length arrays using comparator networks
<p>I have some performance critical code that involves sorting a very short fixed-length array with between around 3 and 10 elements in C++ (the parameter changes at compile time).</p>

<p>It occurred to me that a static sorting network specialised to each possible input size would perhaps be a very efficient way to do this: We do all the comparisons necessary to figure out which case we are in, then do the optimal number of swaps to sort the array. </p>

<p>To apply this, we use a bit of template magic to deduce the array length and apply the correct network:</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;

template&lt; int K &gt;
void static_sort(const double(&amp;array)[K])
{
    cout &lt;&lt; "General static sort\n" &lt;&lt; endl;
}

template&lt;&gt;
void static_sort&lt;3&gt;(const double(&amp;array)[3])
{
    cout &lt;&lt; "Static sort for K=3" &lt;&lt; endl;
}


int main()
{

    double  array[3];

    // performance critical code.
    // ...
    static_sort(array);
    // ...

}
</code></pre>

<p>Obviously it's quite a hassle to code all this up, so:</p>

<ul>
<li>Does anyone have any opinions on whether or not this is worth the effort?</li>
<li>Does anyone know if this optimisation exists in any standard implementations of, for example, std::sort? </li>
<li>Is there an easy place to get hold of code implementing this kind of sorting network?</li>
<li>Perhaps it would be possible to generate a sorting network like this statically using template magic..</li>
</ul>

<p>For now I just use insertion sort with a static template parameter (as above), in the hope that it will encourage unrolling and other compile-time optimisations.</p>

<p>Your thoughts welcome.</p>

<hr>

<p><em><strong>Update:</em></strong>
I wrote some testing code to compare a 'static' insertion short and std::sort. (When I say static, I mean that the array size is fixed and deduced at compile time (presumably allowing loop unrolling etc). 
I get at least a 20% NET improvement (note that the generation is included in the timing). Platform: clang, OS X 10.9.</p>

<p>The code is here <a href="https://github.com/rosshemsley/static_sorting">https://github.com/rosshemsley/static_sorting</a> if you would like to compare it to your implementations of stdlib.</p>

<p>I have still yet to find a nice set of implementations for comparator network sorters.</p>

<hr>