使用多种类型时是否可以减少编译时间?

发布于 2025-01-02 12:44:39 字数 611 浏览 0 评论 0原文

让我们坚持使用一个文件和一个标头。我生成了一个包含大量信息的标头,并制作了该标头的精简版本,删除了许多方法。标头从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贵在坚持 2025-01-09 12:44:39

您可以导出您的定义——当然假设您在其他地方包含此标头。当您查看较大的项目或像 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文