Efficiency and optimization in assignment inside the condition

Is efficiency and optimization in assignment inside the conditional expression quite significant ?
How is to pinpoint the real assembly code enhanced efficiency difference, and
about how many % would it be ?
1
2
3
4
5
a = b(c) * d;
if (a)  cout <<"True";


if ((a = b(c) * d))   cout <<"True";
Last edited on
> Is efficiency and optimization in assignment inside the conditional expression quite significant ?
No.

> How is to pinpoint the real assembly code enhanced efficiency difference,
> and about how many % would it be ?
Zero % difference.


To any decent modern compiler, especially an optimising compiler, both code examples are the same.

You as a programmer should be focussing on bigger issues like making sure you choose the best algorithms and data structures for the problem being solved.

Focus on writing clear code that expresses what you want, and leave the micro-management to the compiler.
Last edited on
It has nothing to do with efficiency. If you remove the semicolon on line 5 so that both snippets do the same thing the compiler will generate the same instructions (at least with optimizations turned on).

https://godbolt.org/z/H-JX2e
Topic archived. No new replies allowed.