3 ms·
Interesting! It'd be nice to benchmark to see if there are any practical difference in terms of speed.
by jcbages 4y ago
Interesting! It'd be nice to benchmark to see if there are any practical difference in terms of speed.
- AnotherGoodName 4y agoYes. In order: A well predicted branch costs 0. This is the best case and why branching code can sometimes be faster. An instruction that needs a previous instruction to compute has some pipeline stalls. This is slower than the above and why branchless code can be slower. A mispredicted branch costs a full pipeline flush. The worst case. This is why we avoid branches but we shouldn't do so blindly since it might not be common in a given program. So it depends. I discourage removing branches in general unless you have benchmarks to back it up.