使用 GEANT4(大型 Monte Carlo C++ 仿真框架,大量共享库)运行仿真代码。使用黄金链接器和基于标准 BFD 的链接器编译并链接 GEANT 和我的应用程序。看起来金色的跑得更快了一点(1'47"对 1'51")。有人可以阐明造成差异的原因是什么吗? Ubuntu 15.04、64 位、GCC 4.9.2。每个测试运行大约 10 次,用时最少,没有其他事件,一个终端。
最佳答案
当然,不同的链接器会产生不同的结果,就像不同的编译器一样。结果主要取决于每个链接器上启用(和可用)的优化选项。这是您看到的差异的一个可能原因,但可能还有许多其他原因:
-fipa-icf
Perform Identical Code Folding for functions and read-only variables. The optimization reduces code size and may disturb unwind stacks by replacing a function by equivalent one with a different name. The optimization works more effectively with link time optimization enabled. Nevertheless the behavior is similar to Gold Linker ICF optimization, GCC ICF works on different levels and thus the optimizations are not same - there are equivalences that are found only by GCC and equivalences found only by Gold.
来自:https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
最后但同样重要的是:除了实际的二进制内容之外,还有许多环境因素会影响运行时。例如,缓存抖动会对执行时间产生相当大的影响。此外,10 次执行的集合对于统计结论来说太小了。
关于c++ - 二进制链接与 gold 链接器运行得更快吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30010588/