🧠
MindDB
  • MindDB
  • About Me
  • Bhaumik Mistry
  • Projects
  • Arsenal
    • Games 2019 2020
  • Count-It
    • 2020 Books
    • 2020 Games
    • 2020 Movies
    • 2020 TV Series
    • 2021 All Information
  • Drawingbook
    • Instagram Drawing Book
    • Pixel art book
    • A to P sketches
      • A
      • B
      • C
      • D
      • E
      • F
      • G
      • H
      • I
      • J
      • K
      • L
      • M
      • N
      • P
  • General Knowledge
    • Travel
    • Memory
    • Anger and Hunger
  • Mac
    • OS X version from command line
    • System setup
  • Physics
    • Aerodynamics
    • James Glashier
  • Space
    • Kepler space telescope
    • K2-18b
    • Parsec
  • Software
    • Advent of Code
    • Android
      • Icons
      • Snippets
    • C++
      • Code
        • If-else Vs Ternary
        • Best Fitting Plane
        • To Do
    • Chrome Extension
    • Git
    • iphone
    • PaaS
      • Heroku
      • Docker
    • People
      • Paul Graham
      • Ben Kuhn
    • Python
      • Pytest
      • UUID
  • Sports
    • Football(soccer)
      • EPL
    • Basketball
  • Stocks
    • TARP
Powered by GitBook
On this page
  • Details on assambly
  • Graphs
  • More discussion and stackOverFlow answer links

Was this helpful?

  1. Software
  2. C++
  3. Code

If-else Vs Ternary

PreviousCodeNextBest Fitting Plane

Last updated 5 years ago

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

Details on assambly

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.

Graphs

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.

Graph

More discussion and stackOverFlow answer links

embeddedgurus
nynaeve
questions/3565368
questions/6754454
if_else.cpp gist
https://gist.github.com/bhaumikmistry/cffd44f80b7beca4860cb1876adb8e33
https://gist.github.com/bhaumikmistry/cffd44f80b7beca4860cb1876adb8e33/#file-if_else-cpp
ternary.cpp gist
available as gist