ronag
ronag

Reputation: 51245

Profiling and Optimizing Compilation

The compilation time of my project is quite long and I'd like to reduce this as much as possible. However, right now I'm just browsing around my project and try to remove compilation heavy stuff on pure intuition.

I would like to be able to profile my compilation on some level which would give me useful information which I can use to identify what is taking most of my compilation time.

I have tried enabling "Build Timing" in Visual Studio but that does not give me more information than timing of the different tasks the compiler is performing, knowing that most time is spent in "CL" is not very helpful.

Is there any way to profile compilation at a lower level such as line or file timing?

Upvotes: 16

Views: 713

Answers (2)

gentlecolts
gentlecolts

Reputation: 23

You should try dividing your code into separate files as much as you can. I don't use visual studio, so I don't know exactly how they handle this, but here is a good guide for the why and how http://www.cplusplus.com/forum/articles/10627/

Upvotes: 0

Jean-Philippe Jodoin
Jean-Philippe Jodoin

Reputation: 4736

I have no compilation profiling advice to offer. However, here's a couple of tips to reduce compilation time:

  • Use Forward declaration in header file as much as possible

    In C++, classes can be forward-declared if you only need to use the pointer-to-that-class type (since all object pointers are the same size, and this is what the compiler cares about). (source: http://en.wikipedia.org/wiki/Forward_declaration)

  • Also, using the Pimpl idiom will help you a lot by allowing the compiler to recompile only the part you've modified. http://en.wikipedia.org/wiki/Opaque_pointer

  • Avoid catch-all include file that contains all the include file of a library and only include the headers you actually need.

Upvotes: 1

Related Questions