c++ - 不同版本的编译器(例如 GCC)会产生不同的性能吗?

标签 c++ c optimization g++ compiler-optimization

我有一个问题很久了,即新版本的 C/C++ 编译器是否生成性能更好的代码(例如 G++ 7.3 vs G++ 4.8)?

如果他们这样做,加速的来源是什么?如果不是,是否建议更新编译器?

最佳答案

这里有一个关于 GCC 的简短回答——在他们的 home website 上有大量不同的基准测试结果。 .

例如,查看 Charles Leggett 的 OOPACK 基准测试的特定运行:

The OOPACK kernels consist of 4 programs to measure the relative performance of C++ compilers vs C compilers for abstract data types. The kernels are constructed in such a way that they can be coded in C or C++. The C programs are compiled by the C++ compiler.

The kernels consist of:

  • Max measures how well a compiler inlines a simple conditional.
  • Matrix measures how well a compiler propagates constants and hoists simple invariants.
  • Iterator measures how well a compiler inlines short-lived small objects.
  • Complex measures how well a compiler eliminates temporaries.

其中一个结论是:

gcc optimized C has somewhat improved between 2.91.66 and 3.x

正如预期的那样,快速浏览一下其他一些基准似乎也支持“越新越好”的说法。

采用 GCC Development Mission Statement 中列出的“设计和开发目标”中的类别,改进的原因属于以下三种之一:

  • New optimizations
  • Improved runtime libraries
  • Various other infrastructure improvements

重要的是要注意其他目标涉及“新语言”和“新目标”——因此新版本的相关性将取决于您的用例。

此外,阅读有关 release criteria 的信息-- 我会警告不要通过谈论一般的“更好的性能”来误导自己,因为编译器设计有很多权衡:

In contrast to most correctness issues, where nothing short of correct is acceptable, it is reasonable to trade off behavior for code quality and compilation time. For example, it may be acceptable, when compiling with optimization, if the compiler is slower, but generates superior code. It may also be acceptable for the compiler to generate inferior code on some test cases if it generates substantially superior code on other test cases.

因此,尤其是对于利基和性能关键的应用程序,您可能希望比较特定的编译器版本


作为旁注,您可能会发现阅读更多关于他们的 development plan 的信息很有趣其中包括版本编号等的解释。

关于c++ - 不同版本的编译器(例如 GCC)会产生不同的性能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59603314/

相关文章:

c - 如何获取 C 中用户输入的历史记录?

mysql - 最佳 MySQL 配置 (my.cnf)

java - 垃圾收集器在没有用户代码运行的情况下在 Tomcat Web 应用程序中频繁运行

c++ - 可变数组 C++

c++ - 安全线程终止

c++ - 忽略 C++ 单元测试

GCC 内联汇编器 "memory"Clobber 不会阻止重新排列 ARM 中的代码

C++ 在类中声明静态枚举与枚举

c - 如何为 EVP_CIPHER 设置零填充?

c - 不明白这段代码是如何缩放bmp图像的