gpt4 book ai didi

c++ - 源代码合并真的能提高 C 或 C++ 程序的性能吗?

转载 作者:太空狗 更新时间:2023-10-29 22:58:54 26 4
gpt4 key购买 nike

<分区>

代码合并包括将整个源代码复制到一个文件中。

例如,它是由 SQLite 完成的减少编译时间并提高生成的可执行文件的性能。在这里,它生成一个包含 184K 行代码的文件。

我的问题不是关于编译时间(已在 this question 中回答),而是关于可执行文件的效率。

SQLite 开发者说:

In addition to making SQLite easier to incorporate into other projects, the amalgamation also makes it run faster. Many compilers are able to do additional optimizations on code when it is contained with in a single translation unit such as it is in the amalgamation. We have measured performance improvements of between 5 and 10% when we use the amalgamation to compile SQLite rather than individual source files. The downside of this is that the additional optimizations often take the form of function inlining which tends to make the size of the resulting binary image larger.

据我了解,这是由于 interprocedural optimization (IPO) 造成的,由编译器进行的优化。

GCC开发人员也这样说(感谢@nwp 提供的链接):

The compiler performs optimization based on the knowledge it has of the program. Compiling multiple files at once to a single output file mode allows the compiler to use information gained from all of the files when compiling each of them.

但他们并没有谈到这样做的最终 yield 。

除了 SQLite 之外,是否有任何测量结果证实或反驳了 IPO with 合并产生比 IPO without 合并更快的可执行文件的说法当用 gcc 编译时?

作为附带问题,关于此优化,进行代码合并或将所有 .cpp(或 .c)文件#include 到一个文件中是一回事吗?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com