Comparisons
Two things routinely conflated, put side by side. Neither column is the winner — what decides is the workload and the machine.
Branch vs Branchless
A well-predicted branch is nearly free — the CPU has already gone the right way. An unpredictable one costs a pipeline refill. Branchless code pays a small fixed cost always, so it wins only when prediction genuinely fails. It is not a universal optimization, and the compiler often does it for you.
Free when predictable; skips work entirely on the untaken path
A misprediction costs a full pipeline refill
The condition is predictable, or the skipped work is substantial
Constant cost regardless of data; no misprediction penalty
Always executes both sides; harder to read; can defeat other optimizations
The condition is genuinely random and the bodies are cheap
| Dimension | Branch | Branchless |
|---|---|---|
| Predictable data | Faster | Slower |
| Random data | Slower | Faster |
| Readability | Better | Usually worse |