I have a C++ code which I am compiling using VC7 and it is taking a lot of time to build it. Is there any way I could profile it and find why it is taking time to build ?
8 Answers
In Visual Studio 2008, there's a setting for turning on build timing. It might be there in VC7 as well...
Tools
/ Options
/ Projects and Solutions
/ VC++ Project Settings
/ Build Timing:
Yes
This applies to C++ projects, which (as of VS2008) don't use MSBuild. For MSBuild-based projects (such as C#), you want to increase the verbosity:
Tools
/ Options
/ Projects and Solutions
/ Build and Run
/ MSBuild project build output verbosity
By default, it's set to "Minimal".

- 89,048
- 55
- 235
- 380
Recent Microsoft's C++ Build Insights SDK has introduced an option /timetrace
to its vcperf which allows you to profile your build and visualise the build times of specific components in form of a flame graph inside of any chromium-based browser.
Assuming you have vcperf
downloaded and installed, you need to:
- Start its session by executing
vcperf /start SessionName
- Run your build (the events are captured system-wide by vcperf)
- Stop the session
vcperf /stop SessionName /timetrace output.json
You can now run your chromium-based browser, type in <browser_name>://tracing
, (for example chrome://tracing
) and load up the output.json
file for visualisation.
Example visualisation taken from here.

- 51
- 1
- 2
-
This works also with Visual Studio 2017. The display is more messy (the names are mangled) but still very useful. – anatolyg Jan 06 '21 at 15:14
If the code is template-intensive, then you could try doing the template instantiation profiling. Steven Watanabe came up with the profiler and if I remember correctly it was supposed to work with VS (don't know the version).

- 18,162
- 2
- 41
- 64
-
+1, templates can hit comilation time badly, even with precompiled headers – SmacL Feb 17 '09 at 11:20
Is the source code on a network? This sometimes slows the compilation a lot.

- 52,876
- 38
- 145
- 202
-
-
Never ever use a dynamic view for source code. it's way more trouble than its worth. – shoosh Feb 17 '09 at 10:32
If your code makes extensive use of template, you might be interested in Templight, a tool developed by a hungarian research team for debugging and profiling C++ template metaprograms (paper). It seems very promising, but I'm not sure the tool is available for download...

- 79,925
- 15
- 92
- 137
-
1Templight is on the way of becoming builtin feature in clang. The current version and the visualizer tool can be found here: http://plc.inf.elte.hu/templight/ – jmihalicza Feb 01 '14 at 11:59
My guess is that it would be difficult to get useful results from profiling. You could look at the create times of each .obj file and check if there are any files that are particularly slow, but I doubt this would be the case.
Have you gone through the compiler options such as pre-compiled headers to see what improvements ths provides? Similarly, turning off the optimizer where it is not required can speed the build up significantly. My advice would be to take some time to try out a few 'what if' scenarios.

- 22,555
- 12
- 95
- 149
You can try if possible in your situation the trick of #include all .cpp files into a single compilation unit, just for the purpose of checking if you have much overhead from many files and many includes.

- 76,898
- 55
- 205
- 325
-
Unfortunately, templates are only instantiated by complete translation units, not in precompiled headers. When I tried using precompiled headers for my template-heavy project, they only improved compile time by 0-5% (whether with optimizations on or off!). If C++17 brings us modules, they might help... – idupree Apr 04 '13 at 16:24