How can i create a table to get compilation time of each c++ file in visual studio 2005 project.
3 Answers
I am using Visual Studio 2010 but other versions of Visual Studio may have something similar. In VS2010 you may add to the command line options /Bt+ which prints the time taken to compile each file. So in a project properties under "Configuration Properties" -> "C/C++" -> "Command Line" -> "Additional Options" add /Bt+
Setting the /Bt+ option results in the output (which is recorded in the log file) lines like the following:
time(c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\c1.dll)=0.05110s < 25394686804 - 25394831194 > BB [C:\not-important\nlopt-2.4.2\direct\DIRect.c]
More information on this option at https://blogs.msdn.microsoft.com/vcblog/2010/04/01/vc-tip-get-detailed-build-throughput-diagnostics-using-msbuild-compiler-and-linker/ which I found thanks to this answer https://stackoverflow.com/a/3513043/453436
There are plenty of ways to extract the time lines depending on what tools you have available to you. I did it under a bash shell with a combination of find, grep and perl. The following will give you the compilation time sorted with longest first.
find . -name '*.log' | xargs grep time | perl -ne '$_ =~ /=(.*?)s.*\[(.*)\]/; print "$1 $2\n";' |sort -rn

- 1
- 1

- 2,798
- 23
- 20
-
Thanks! I use VS2013 and this indeed shows compilation time per file. Using the "Build Timing" option as mentioned in another answer only shows compilation/link times per project. – opetroch Dec 25 '16 at 10:25
"Tools" -> "Options" -> "Projects and Solutions" -> "VC++ Project Settings"
Tick "Build Timing".

- 82,554
- 44
- 203
- 280
-
1
-
2Build Timing gives times for the various build processes, not for each file. – Jesse Elliott Feb 22 '17 at 23:19
It's been a while since I've used that version of the compiler, but I recall it prints the name of the file it's compiling to the console (when you use the command line build). If that's the case, then you can write a program that does the following:
- CreateProcess on the command line compiler, redirecting stdout to a pipe
- Read from the pipe, looking for source file names
- Each time a source file name is seen, note the current timestamp
- When the pipe is closed, print out the times taken for each file build
While this approach could be developed in C++, it would likely be easier to use a tool such as Perl to implement it.

- 951,095
- 183
- 1,149
- 1,285
-
-
-
1could you give some lines of code to perform this???? hope i m not bothering you.. – Jul 10 '09 at 11:33