Search code examples
c++optimization

Does building the compiler from source result in better optimization?


Consider this simple case scenario:

I download the pre-built binaries of a C++ compiler (say CLang or GCC or anything else) for my generic OS (that is not windows). I compile my code which consists of some computationally expensive mathematical calculation with optimization flag -O3 and I have an execution time of T1.

On a different attempt, this time instead of using pre-built binaries I download the source code and build the compiler by myself on my generic machine. I compile the same code with the same optimization flag, achieving execution time T2?

Will T2 < T1 or they will be more or less the same?

In other words, is the execution time independent from the way that compiler is built?


Solution

  • The compiler's optimization of your code is the result of the behavior of the compiler, not the performance of the compiler.

    As long as the compiler has the same behavioral design, it will produce exactly the same output.