c++visual-c++profilingbuild-time

How do I find out where the compiler spends its time?


How do I find out where the compiler spends its time?

My build is too slow, I'm already using a RAMdisk for the VC++ temporary files and it doesn't make any difference. (I have an SSD, so I expected no difference.)

Most single C++ files in this project take approx. 2 seconds to compile which seems awful (as I also don't have any in-project parallelization because I'm using VS2005).

How can I optimize this? Don't optimize without profiling, but how do I profile the compiler?

Note: These were not really helpful:


Let's add a good comment: Do you have lot's of templates? How large are your files on average? Do you checked on including only the minimum of necessary headers

No, I did not. I could (and pro'lly will) of course. I may be able to find something, but it's all speculation and trial and error!

"Everybody" tells you that you should only optimize after measuring/profiling, but when optimizing compilation times, we're back to trial&error?


Note: The proposed "hack" from the comments with __TIME__ does not work, at least not on Visual-C++, because (as the docs state): The most recent compilation time of the current source file. The time is a string literal of the form hh:mm:ss. -- I guess one could at least get timings for single compilations units with this stamp, but it doesn't help to drill down into an compilation unit.


Solution

  • TL;DR : Use MS vcperf to analyse your Build.

    Note: This question is from 2013 and the tooling from 2019, so, yep, there was some wait here. :-)

    MS has released vcperf which builds on their C++ Build Insights which is basically a toolchain allowing you to profile the compilation process.

    https://devblogs.microsoft.com/cppblog/introducing-c-build-insights/

    C++ Build Insights makes use of vcperf, a tool that allows you to capture a trace of your build and to view it in the Windows Performance Analyzer (WPA).