C++ Compilation Process – Profiling Techniques

c++compilationprofiling

I tend to write rather large templated header-only C++ libraries and my users commonly complain about compilation times. After thinking about the matter, it occurred to me that I have no idea where the time is going. Is there some simple way to profile the C++ compilation process with common compilers, such as GCC (g++), Intel C++ Compiler (icc), and XL C/C++ (xlC)? For instance, is it possible to get an idea of how much time is spent within each of the phases of C++ compilation?

Best Answer

For GCC there are debugging options to find how much time is spent within each of the phases of C++ compilation?

-Q Makes the compiler print out each function name as it is compiled, and print some statistics about each pass when it finishes.

-ftime-report Makes the compiler print some statistics about the time consumed by each pass when it finishes.

Passes are described in GCCINT 9: Passes and Files of the Compiler.

You can post output of g++ compilation of single source file with -v -ftime-report here to discuss it. There could be some help on the GCC mailing list.


For compilers other than GCC (or GCC more ancient than 3.3.6), see the other options in other answers.

Related Question