3 ms·
That (very interesting) pvk.ca blog post seems consistent with the schani.wordpress.com one. In particular, while pvk mentions preferring linear search and scha
by scottlamb 12y ago
That (very interesting) pvk.ca blog post seems consistent with the schani.wordpress.com one. In particular, while pvk mentions preferring linear search and schani mentions preferring binary search, those preferences are for slightly different cases. schani says:
> If you’re very, very serious about performance and know the array size statically, completely unroll the binary search.
and pvk says:
> I’ll focus on one specific case that is of interest to me: searching a short or medium-length sorted vector of known size.
"Known" here means "known at compile time". And of course he concludes:
> In general, I’d just stick to binary search: it’s easy to get good and consistent performance from a simple, portable implementation.
Both bloggers use conditional moves to avoid conditional branches; use unrolled versions; and of course use benchmarks to arrive at their conclusions.