You are not logged in.

#1 2015-12-11 14:32:37

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 861

Why gcc is much slower when using -std=c++11?

I recently started to build my code with the -std=c++11 gcc flag. I noticed a sizeable slow down of the compilation process, even for code that does not embed any c++11 feature. For example, compiling a minimal hello world I get this:

$ g++ -std=c++98 test.cpp -ftime-report

Execution times (seconds)
 phase setup             :   0.00 ( 0%) usr   0.00 ( 0%) sys   0.02 ( 3%) wall    1135 kB ( 6%) ggc
 phase parsing           :   0.23 (96%) usr   0.08 (100%) sys   0.55 (92%) wall   16075 kB (92%) ggc
 phase opt and generate  :   0.01 ( 4%) usr   0.00 ( 0%) sys   0.03 ( 5%) wall     193 kB ( 1%) ggc
 |name lookup            :   0.05 (21%) usr   0.00 ( 0%) sys   0.06 (10%) wall    1062 kB ( 6%) ggc
 |overload resolution    :   0.01 ( 4%) usr   0.00 ( 0%) sys   0.01 ( 2%) wall     148 kB ( 1%) ggc
 callgraph construction  :   0.00 ( 0%) usr   0.00 ( 0%) sys   0.01 ( 2%) wall      57 kB ( 0%) ggc
 preprocessing           :   0.02 ( 8%) usr   0.03 (38%) sys   0.15 (25%) wall     926 kB ( 5%) ggc
 parser (global)         :   0.07 (29%) usr   0.02 (25%) sys   0.13 (22%) wall    6529 kB (37%) ggc
 parser struct body      :   0.05 (21%) usr   0.01 (13%) sys   0.07 (12%) wall    2849 kB (16%) ggc
 parser enumerator list  :   0.00 ( 0%) usr   0.00 ( 0%) sys   0.02 ( 3%) wall      44 kB ( 0%) ggc
 parser function body    :   0.02 ( 8%) usr   0.00 ( 0%) sys   0.04 ( 7%) wall     968 kB ( 6%) ggc
 parser inl. func. body  :   0.01 ( 4%) usr   0.00 ( 0%) sys   0.02 ( 3%) wall     356 kB ( 2%) ggc
 parser inl. meth. body  :   0.01 ( 4%) usr   0.01 (12%) sys   0.06 (10%) wall    1186 kB ( 7%) ggc
 template instantiation  :   0.04 (17%) usr   0.01 (12%) sys   0.06 (10%) wall    3244 kB (19%) ggc
 varconst                :   0.01 ( 4%) usr   0.00 ( 0%) sys   0.00 ( 0%) wall       0 kB ( 0%) ggc
 rest of compilation     :   0.01 ( 4%) usr   0.00 ( 0%) sys   0.02 ( 3%) wall      19 kB ( 0%) ggc
 TOTAL                 :   0.24             0.08             0.60              17478 kB
$ g++ -std=c++11 test.cpp -ftime-report

Execution times (seconds)
 phase setup             :   0.00 ( 0%) usr   0.00 ( 0%) sys   0.02 ( 2%) wall    1311 kB ( 4%) ggc
 phase parsing           :   0.36 (90%) usr   0.13 (93%) sys   0.81 (90%) wall   28472 kB (90%) ggc
 phase lang. deferred    :   0.03 ( 8%) usr   0.01 ( 7%) sys   0.05 ( 6%) wall    1484 kB ( 5%) ggc
 phase opt and generate  :   0.01 ( 3%) usr   0.00 ( 0%) sys   0.02 ( 2%) wall     283 kB ( 1%) ggc
 |name lookup            :   0.10 (25%) usr   0.02 (14%) sys   0.14 (16%) wall    2250 kB ( 7%) ggc
 |overload resolution    :   0.03 ( 8%) usr   0.01 ( 7%) sys   0.10 (11%) wall    1391 kB ( 4%) ggc
 preprocessing           :   0.05 (12%) usr   0.04 (29%) sys   0.17 (19%) wall    1146 kB ( 4%) ggc
 parser (global)         :   0.05 (13%) usr   0.04 (29%) sys   0.13 (14%) wall   11860 kB (38%) ggc
 parser struct body      :   0.07 (18%) usr   0.02 (14%) sys   0.18 (20%) wall    4745 kB (15%) ggc
 parser enumerator list  :   0.00 ( 0%) usr   0.00 ( 0%) sys   0.02 ( 2%) wall      58 kB ( 0%) ggc
 parser function body    :   0.04 (10%) usr   0.02 (14%) sys   0.03 ( 3%) wall    1020 kB ( 3%) ggc
 parser inl. func. body  :   0.00 ( 0%) usr   0.00 ( 0%) sys   0.06 ( 7%) wall     733 kB ( 2%) ggc
 parser inl. meth. body  :   0.04 (10%) usr   0.00 ( 0%) sys   0.06 ( 7%) wall    1864 kB ( 6%) ggc
 template instantiation  :   0.14 (35%) usr   0.02 (14%) sys   0.21 (23%) wall    8495 kB (27%) ggc
 thread pro- & epilogue  :   0.00 ( 0%) usr   0.00 ( 0%) sys   0.01 ( 1%) wall       4 kB ( 0%) ggc
 rest of compilation     :   0.01 ( 3%) usr   0.00 ( 0%) sys   0.01 ( 1%) wall      19 kB ( 0%) ggc
 TOTAL                 :   0.40             0.14             0.90              31570 kB

This is a 50% increase in wall time; I don't know how this number scales for more complex translation units but there is certainly a sizeable slow down. I know that c++11 is more complex than c++98 and that a slow down might be expected, but do these figures make sense? Or maybe there is something wrong with c++11 in gcc (hard to believe, but...)? Thanks.

Offline

#2 2015-12-11 21:06:03

anatolik
Developer
Registered: 2012-09-27
Posts: 458

Re: Why gcc is much slower when using -std=c++11?

240ms for a test is tooo small time resolution. If you want to have a representable benchmark result then you need to have much larger test, something that lasts minutes.


Read it before posting http://www.catb.org/esr/faqs/smart-questions.html
Ruby gems repository done right https://bbs.archlinux.org/viewtopic.php?id=182729
Fast initramfs generator with security in mind https://wiki.archlinux.org/index.php/Booster

Offline

#3 2015-12-12 10:21:57

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 861

Re: Why gcc is much slower when using -std=c++11?

How did you determine the 240 ms resolution? I repeated the test above many times and the fluctuations I got are far less than the difference I reported in my previous post ; so I'd say that the resolution is adequate and far better than 240 ms. Anyway, I noticed the slow down at first in compiling a large simulation library: I don't have an estimate of the slow down but my feeling is that compile time increased by over half a hour from the previous value of about 1 hour.

Offline

#4 2015-12-12 15:30:41

Octoploid
Member
From: Berlin, Germany
Registered: 2009-10-13
Posts: 64

Re: Why gcc is much slower when using -std=c++11?

These slowdowns are normally caused by the new allocator support of the std library.
See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60976

Offline

#5 2015-12-14 09:14:34

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 861

Re: Why gcc is much slower when using -std=c++11?

Thanks Octoploid. This seems to be the usual no-go issue in free software, namely a bug/regression which has been reported more than a year and a half ago which is still unconfirmed in the bug tracker and that is probably going nowhere. I'll try to use clang for all my builds from now on, it's faster and error reports are orders of magnitude more understandable than gcc ones (debugging an error in template metaprogramming with gcc is a suicide).

Offline

Board footer

Powered by FluxBB