If-else Vs Ternary
Last updated
Was this helpful?
Last updated
Was this helpful?
If else vs Ternary comparison in c++.
The actual code for If-else is very simple but it could be lengthy however for Teranary it can be complicated but short.
Example
VS
Using gcc -S file_name
you can create assambly code alos . The assambly code comes out to be equal for both files as you'll see the int initialization can be seen different, and that is the only difference in the file with gcc --version
which is gcc.exe (i686-win32-dwarf-rev1, Built by MinGW-W64 project) 7.2.0
.
After running in loop n=41000000
I have collected some data and the chart shows simple answer as the iteration goes up the difference in time execution also grows.