开发者

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 ju开发者_如何学Cst 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?


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.


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜