使用多种类型时是否可以减少编译时间?
让我们坚持使用一个文件和一个标头。我生成了一个包含大量信息的标头,并制作了该标头的精简版本,删除了许多方法。标头从 6k 行增加到 3k。
下面是一个类在轻标头中的样子的示例,
class SomeClass : public MACRO_FOR_KEYWORD TheBase {
virtual void i_dont_filter_this_out(){}
public:
deque<Var*> ls;
inline SomeClass(){}
inline virtual ~SomeClass(){}
inline SomeClass(deque<Var*> ls_)
{
ls = ls_;
}
};
我尝试编译相同的文件,它从 8 秒变为 7 秒......这不是我希望的结果。
我想也许大部分编译时间是因为我定义了很多类,而方法并不重要。但我需要所有这些课程都存在。大约有280个班级。我认为不多。
我可以做些什么来缩短编译时间?我应该打扰吗?每个文件大约需要 9 秒,链接又需要几秒钟。我想除了获得更快的CPU之外我什么也做不了?
注意:我正在使用视觉工作室。
Lets stick with one file and one header. I generate a header which has lots of information in it and i make a light version of that header with many methods removed. The header went from 6k lines to 3k.
Here is an example of how a class looks like in the light header
class SomeClass : public MACRO_FOR_KEYWORD TheBase {
virtual void i_dont_filter_this_out(){}
public:
deque<Var*> ls;
inline SomeClass(){}
inline virtual ~SomeClass(){}
inline SomeClass(deque<Var*> ls_)
{
ls = ls_;
}
};
I tried compiling the same file and it went from 8seconds to 7seconds... Not the results i was hoping for.
I'm thinking maybe the majority of the compile time is because i am defining so many classes and the methods don't matter. But i need all thoses classes to exist. Theres about 280 classes. I don't think thats many.
What can i do to lower my compile time? Should i bother? Its about 9seconds per file and linking is another few seconds. I don't suppose i can do anything but get a faster CPU?
Note: I am using visual studios.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以导出您的定义——当然假设您在其他地方包含此标头。当您查看较大的项目或像 boost 这样的库时,280 个类相当小。这些类是否都属于一起 - 或者它们不能分成更小的组以减少依赖性和编译时间?为什么您应该青睐轻量标头(带有冗余声明?)而不是统一构建等方法?
You can export your definitions -- assuming of course you include this header elsewhere. 280 classes is quite small when you look at larger projects or libraries like boost. Do these classes all belong together - or can they not be separated into smaller groups to reduce dependency and compile times? Why should you favor a light header (with redundant declaration?) over an approach such as a unity build?