简体   繁体   English

分析和优化编译

[英]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. 我已经尝试在Visual Studio中启用“ Build Timing”,但是,除了了解编译器正在执行的不同任务的时间安排之外,它没有给我更多的信息,但要知道大多数时间都花在了“ CL”上不是很有帮助。

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). 在C ++中,如果只需要使用指向该类的指针类型,则可以向前声明类(因为所有对象指针的大小都相同,而这正是编译器所关心的)。 (source: http://en.wikipedia.org/wiki/Forward_declaration ) (来源: 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. 另外,使用Pimpl惯用语将允许编译器仅重新编译已修改的部分,从而对您有很大帮助。 http://en.wikipedia.org/wiki/Opaque_pointer 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/ 我不使用Visual Studio,所以我不确切知道它们如何处理,但是这里有一个很好的指南,说明了为什么以及如何http://www.cplusplus.com/forum/articles/10627/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM