MarkB
MarkB

Reputation: 892

Why does g++ take much longer to compile <algorithm> with -std=c++11?

g++ version is 5.3.0.

#include <algorithm>
int main() {
    return 0;
}

test$ time g++ test.cpp

real    0m0.203s
user    0m0.073s
sys     0m0.031s

test$ time g++ test.cpp --std=c++11

real    0m0.761s
user    0m0.554s
sys     0m0.130s

Similar results over multipfle attempts. Only a minor slowdown (0.03s) with including the vector header.

Upvotes: 0

Views: 146

Answers (1)

user9154776
user9154776

Reputation: 131

The straight forward answer is that there is obviously more to compile. Using -Q -ftime-report GCC will print out profile statistics. Keep in mind that the section on the left is not reliable because it changes everytime you run the command, but the TOTAL is always consistent. For C++03 and C++11 respectively:

Execution times (seconds)
 phase setup             :   0.00 ( 0%) usr   0.00 ( 0%) sys   0.00 ( 0%) wall    1189 kB (16%) ggc
 phase parsing           :   0.03 (100%) usr   0.02 (100%) sys   0.06 (100%) wall    6301 kB (83%) ggc
 preprocessing           :   0.01 (33%) usr   0.01 (50%) sys   0.04 (67%) wall     488 kB ( 6%) ggc
 parser (global)         :   0.00 ( 0%) usr   0.01 (50%) sys   0.00 ( 0%) wall    3626 kB (48%) ggc
 parser struct body      :   0.02 (67%) usr   0.00 ( 0%) sys   0.01 (17%) wall     778 kB (10%) ggc
 parser function body    :   0.00 ( 0%) usr   0.00 ( 0%) sys   0.01 (17%) wall     436 kB ( 6%) ggc
 TOTAL                 :   0.03             0.02             0.06               7558 kB

Execution times (seconds)
 phase setup             :   0.00 ( 0%) usr   0.00 ( 0%) sys   0.00 ( 0%) wall    1384 kB (11%) ggc
 phase parsing           :   0.05 (100%) usr   0.03 (100%) sys   0.10 (100%) wall   10953 kB (88%) ggc
 |name lookup            :   0.00 ( 0%) usr   0.01 (33%) sys   0.01 (10%) wall    1301 kB (10%) ggc
 preprocessing           :   0.01 (20%) usr   0.00 ( 0%) sys   0.03 (30%) wall     878 kB ( 7%) ggc
 parser (global)         :   0.01 (20%) usr   0.01 (33%) sys   0.01 (10%) wall    4592 kB (37%) ggc
 parser struct body      :   0.02 (40%) usr   0.00 ( 0%) sys   0.01 (10%) wall    2837 kB (23%) ggc
 parser function body    :   0.01 (20%) usr   0.01 (33%) sys   0.01 (10%) wall     478 kB ( 4%) ggc
 parser inl. meth. body  :   0.00 ( 0%) usr   0.01 (33%) sys   0.03 (30%) wall     937 kB ( 8%) ggc
 symout                  :   0.00 ( 0%) usr   0.00 ( 0%) sys   0.01 (10%) wall       0 kB ( 0%) ggc
 TOTAL                 :   0.05             0.03             0.10              12490 kB

That's a difference of 12490 - 7558 = 4942 KB, not that big of a difference. Now as to why there's such a big difference in GCC 5.3.0, it's a QoI issue that's probably been fixed in later releases.

Upvotes: 1

Related Questions