https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71995

            Bug ID: 71995
           Summary: ~36% compile-time performance regression for C++ in
                    gcc HEAD vs gcc-6-branch HEAD
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tom at honermann dot net
  Target Milestone: ---

A compile-time performance degradation in gcc HEAD (r238592) vs gcc-6-branch
HEAD (r238587) was observed while verifying performance improvements for bug
67565.  Though that bug was specific to C++ concepts, the performance
regression is not.

In my tests both the gcc and gcc-6-branch compilers were built using the Ubuntu
15.10 x86_64 distribution of gcc 5.2.1:

$ gcc --version
gcc (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010
...

Both gcc builds were configured and built with:
  $ ./configure \
    CC=gcc \
    CXX=g++ \
    --prefix /path/to/install/... \
    --disable-multilib \
    --disable-bootstrap \
    --enable-languages=c,c++
  $ make
  $ make install

The following code was used for testing:

$ cat t.cpp
/*
 * Test adapted from:
 * https://randomascii.wordpress.com/2014/03/10/making-compiles-slow
 */
#if !defined(SCALE_FACTOR)
#define SCALE_FACTOR 23
#endif
template<int R, int N>
struct slow_fibonacci {
    static constexpr int value =
        slow_fibonacci<R, N-1>::value +
        slow_fibonacci<R + (1<<N), N-2>::value;
};
template<int R>
struct slow_fibonacci<R,2> {
    static constexpr int value = 1;
};
template<int R>
struct slow_fibonacci<R,1> {
    static constexpr int value = 1;
};
constexpr int x = slow_fibonacci<0,SCALE_FACTOR>::value;

The test was performed three times at each of three scale factors for each
compiler build, the times averaged for each scale factor, and then percentages
calculated.

Compile times using the gcc trunk build:
# default SCALE_FACTOR=23
$ time g++ -c -std=c++11 t.cpp
real    0m02.079s  |  real    0m02.089s  |  real    0m02.070s
user    0m02.004s  |  user    0m02.016s  |  user    0m02.000s
sys     0m00.068s  |  sys     0m00.068s  |  sys     0m00.064s
# SCALE_FACTOR=25
$ time g++ -c -std=c++11 -DSCALE_FACTOR=25 t.cpp
real    0m05.401s  |  real    0m05.431s  |  real    0m05.428s
user    0m05.224s  |  user    0m05.272s  |  user    0m05.224s
sys     0m00.172s  |  sys     0m00.156s  |  sys     0m00.204s
# SCALE_FACTOR=27
$ time g++ -c -std=c++11 -DSCALE_FACTOR=27 t.cpp
real    0m14.268s  |  real    0m14.379s  |  real    0m14.654s
user    0m13.912s  |  user    0m13.900s  |  user    0m14.332s
sys     0m00.356s  |  sys     0m00.480s  |  sys     0m00.320s

Compile times using the gcc-6-branch build:
# default SCALE_FACTOR=23
$ time g++ -c -std=c++11 t.cpp
real    0m01.466s  |  real    0m01.432s  |  real    0m01.441s
user    0m01.384s  |  user    0m01.320s  |  user    0m01.356s
sys     0m00.076s  |  sys     0m00.108s  |  sys     0m00.080s
# SCALE_FACTOR=25
$ time g++ -c -std=c++11 -DSCALE_FACTOR=25 t.cpp
real    0m04.076s  |  real    0m04.072s  |  real    0m04.366s
user    0m03.868s  |  user    0m03.920s  |  user    0m04.208s
sys     0m00.204s  |  sys     0m00.148s  |  sys     0m00.152s
# SCALE_FACTOR=27
$ time g++ -c -std=c++11 -DSCALE_FACTOR=27 t.cpp
real    0m10.658s  |  real    0m10.701s  |  real    0m10.779s
user    0m10.096s  |  user    0m10.292s  |  user    0m10.368s
sys     0m00.560s  |  sys     0m00.408s  |  sys     0m00.412s

-------------+---------------+------------------+---------------------+
SCALE_FACTOR | gcc trunk avg | gcc-6-branch avg | % change            |
-------------+---------------+------------------+---------------------+
23           |        2.079s |           1.446s | +43.776% / -30.447% |
25           |        5.420s |           4.171s | +29.945% / -23.044% |
27           |       14.434s |          10.713s | +34.734% / -25.779% |
-------------+---------------+------------------+---------------------+

Averaging the percentages suggests ~36% performance overhead for gcc trunk vs
gcc-6-branch.

Reply via email to