Profiling the C++ compilation process

前端 未结 7 907
栀梦
栀梦 2020-11-28 19:48

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 t

相关标签:
7条回答
  • 2020-11-28 20:22

    You can separate them out to some extent (I'm assuming make)

    • add a build rule that only preprocesses files (using the -E switch), and a .PHONY target that depends on the preprocessor output files just like the normal binary target depends on .o files. Measure how long it takes to build this target
    • add a 'PHONY target that depends on all the .o files but doesn't link them. Measure how long it takes to build this target (from clean)
    • measure how long it takes to do a clean build of the usual binary

    Now you have some idea how long it takes to pre-process, compile, and link. You can also compare optimized and non-optimized (-O0) versions of the second and third target, to see how long is spent in the optimizer.

    0 讨论(0)
提交回复
热议问题