[Solved] if-else vs if performance


There is no performance difference since the generated code is exactly the same:

$ echo "int main() { int number; if (number == 0) return -1; return 0; }" | g++ -x c++ -S - -o /dev/stdout | md5sum
9430c430d1f748cc920af36420d160ce  -

$ echo "int main() { int number; if (number == 0) return -1; else {} return 0; }" | g++ -x c++ -S - -o /dev/stdout | md5sum
9430c430d1f748cc920af36420d160ce  -

$ echo "int main() { int number; if (number == 0) return -1; else {} return 0; }" | g++ -x c++ -S - -o /dev/stdout 
    .file   ""
    .text
    .globl  main
    .type   main, @function
main:
.LFB0:
    .cfi_startproc
    pushq   %rbp
    .cfi_def_cfa_offset 16
    .cfi_offset 6, -16
    movq    %rsp, %rbp
    .cfi_def_cfa_register 6
    cmpl    $0, -4(%rbp)
    jne .L2
    movl    $-1, %eax
    jmp .L3
.L2:
    movl    $0, %eax
.L3:
    popq    %rbp
    .cfi_def_cfa 7, 8
    ret
    .cfi_endproc
.LFE0:
    .size   main, .-main
    .ident  "GCC: (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4"
    .section    .note.GNU-stack,"",@progbits

solved if-else vs if performance