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.

Strengths

Free when predictable; skips work entirely on the untaken path

Costs

A misprediction costs a full pipeline refill

Use when

The condition is predictable, or the skipped work is substantial

BranchlessOpen lesson →
Strengths

Constant cost regardless of data; no misprediction penalty

Costs

Always executes both sides; harder to read; can defeat other optimizations

Use when

The condition is genuinely random and the bodies are cheap

DimensionBranchBranchless
Predictable dataFasterSlower
Random dataSlowerFaster
ReadabilityBetterUsually worse