3 ms·
True, I had hoped GCC would optimize that -- it doesn't :(.
by stabbles 9y ago
True, I had hoped GCC would optimize that -- it doesn't :(.
- xamuel 9y agoIt would make no sense for GCC to automatically add early-exit: that requires a judgement call about the vectors the function is intended to run on. A priori, the function might be intended to run on vectors that are almost always sorted, in which case the extra branch would be severely suboptimal.
- banachtarski 9y agoI agree that the optimization isn't possible but this is for correctness reasons. The performance penalty of the extra branch is almost negligible due to branch prediction.
- deleted 9y ago[deleted]