Question: I argued with a friend the other day about those two snippets. Which is faster and why ?

```
value = 5;
if (condition) {
    value = 6;
}

```

and:

```
if (condition) {
    value = 6;
} else {
    value = 5;
}

```

What if `value` is a matrix ?

Note: I know that `value = condition ? 6 : 5;` exists and I expect it to be faster, but it wasn't an option.

**Edit** (requested by staff since question is on hold at the moment):

* please answer by considering either *x86 assembly* generated by mainstream compilers (*say g++, clang++, vc, mingw*) in both optimized and non optimized versions or *MIPS assembly*.
* when assembly differ, explain why a version is faster and when (*e.g. "better because no branching and branching has following issue blahblah"*)

Answer: 
In unoptimised code, the first example assigns a variable always once and sometimes twice. The second example only ever assigns a variable once. The conditional is the same on both code paths, so that shouldn't matter. In optimised code, it depends on the compiler.

As always, if you are that concerned, generate the assembly and see what the compiler is actually doing.
Ok, since assembly is one of the tags, I will just assume your code is pseudo code (and not necessarily c) and translate it by human into 6502 assembly.

1st Option (without else)

```
        ldy #$00
        lda #$05
        dey
        bmi false
        lda #$06
false   brk

```

2nd Option (with else)

```
        ldy #$00
        dey
        bmi else
        lda #$06
        sec
        bcs end
else    lda #$05
end     brk

```

Assumptions: Condition is in Y register set this to 0 or 1 on the first line of either option, result will be in accumulator.

So, after counting cycles for both possibilities of each case, we see that the 1st construct is generally faster; 9 cycles when condition is 0 and 10 cycles when condition is 1, whereas option two is also 9 cycles when condition is 0, but 13 cycles when condition is 1. (*cycle counts do not include the `BRK` at the end*).

**Conclusion: `If only` is faster than `If-Else` construct.**

And for completeness, here is an optimized `value = condition + 5` solution:

```
ldy #$00
lda #$00
tya
adc #$05
brk

```

This cuts our time down to 8 cycles (*again not including the `BRK` at the end*).