Search code examples
performancecompiler-construction

Are programming languages converted in machine code by compilers?


If so, why different programs written in different languages have different execution speeds?


Solution

  • Though programs written in different languages are converted into machine code at the end of the day, different languages have different implementation to say same thing.

    You can take analogy from human languages e.g the English statement I am coming home. is translated to Chinese as 我未来的家。, as you can see the Chinese one is more concise though it is not always true; same concept applies to programming languages.

    So in the case of programming languages a machine code X can be written in programming language A as 2X-X, programming language B as X/2 + X/2...but executing machine code X and 2X-X will result same result though their performance wont same ( this is hypothetical example but hope it makes sense.)

    Basically it is not guaranteed that a program with same output written in different programming languages results in same machine code, but is converted into a machine code that gives same output, that where the difference comes.

    But this will give you thorough info