Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do different versions of compilers (e.g GCC) generate different performance?

I have a question for a long time, i.e. whether the new version of C/C++ compiler generate better code with better performance (e.g. G++ 7.3 vs G++ 4.8)?

If they do, what is the source of speedup? If not, is it recommended to update the compilers?

like image 433
Zhihao Cui Avatar asked Nov 17 '25 08:11

Zhihao Cui


2 Answers

Here's a short answer regarding GCC -- there's an extensive list of different benchmark results available on their home website.

For example, looking at a specific run of the OOPACK benchmark by Charles Leggett:

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.

one of the conclusions reads:

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

As expected, having a quick look at some other benchmarks also seems to support the narrative that "newer is better".

Taking the categories from the "Design and Development Goals" listed in the GCC Development Mission Statement, the reasons for improvements fall into one of the three:

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

It is important to note that other goals involve "new languages" and "new targets" -- thus the relevance of a new version will be dependent on your use case.

Moreover, reading about the release criteria -- I'd warn against possibly misleading yourself by speaking about "better performance" in general, as compiler designs come with many trade-offs:

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.

Thus, especially with niche and performance-critical applications you might want to compare specific compiler versions


As a side note, you might find it interesting to read more about their development plan that includes the explanation of the version numbering etc.

like image 167
gstukelj Avatar answered Nov 18 '25 21:11

gstukelj


Yes, newer versions of GCC generate better code and have better performance.

The speedup is from better code-generating algorithms written into GCC.

I would recommend upgrading GCC if there aren't compatibility issues. Newer GCC versions have fewer bugs and generate better code.

You may have to upgrade Binutils too if you upgrade GCC.


Just a note to clarify, this probably doesn't apply to any Microsoft products (see comments). As I don't have any experience with them, I don't know. In general, however, GCC has fewer bugs and better code with each release, which is why I wrote what I did.

like image 35
S.S. Anne Avatar answered Nov 18 '25 21:11

S.S. Anne