[Bug c++/80826] New: Compilation Time for many of std::map insertions
seanthesheep1 at hotmail dot com
gcc-bugzilla@gcc.gnu.org
Fri May 19 10:10:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80826
Bug ID: 80826
Summary: Compilation Time for many of std::map insertions
Product: gcc
Version: 4.8.5
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: seanthesheep1 at hotmail dot com
Target Milestone: ---
Created attachment 41388
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41388&action=edit
test code
Hi,
I have some code, which I am attempting to generate from file, which creates a
std::map<std::string, int> and inserts 6000+ pairs into it.
Here is sample code what I mean:
#include <iostream>
#include <stdlib.h>
#include <map>
#include <string>
int main ()
{
std::map<std::string, int> mMap;
mMap.insert (std::pair<std::string, int>("1", 1));
mMap.insert (std::pair<std::string, int>("2", 2));
mMap.insert (std::pair<std::string, int>("3", 3));
mMap.insert (std::pair<std::string, int>("4", 4));
mMap.insert (std::pair<std::string, int>("5", 5));
mMap.insert (std::pair<std::string, int>("6", 6));
mMap.insert (std::pair<std::string, int>("7", 7));
mMap.insert (std::pair<std::string, int>("8", 8));
mMap.insert (std::pair<std::string, int>("9", 9));
mMap.insert (std::pair<std::string, int>("10", 10));
mMap.insert (std::pair<std::string, int>("11", 11));
mMap.insert (std::pair<std::string, int>("12", 12));
mMap.insert (std::pair<std::string, int>("13", 13));
mMap.insert (std::pair<std::string, int>("14", 14));
//...
mMap.insert (std::pair<std::string, int>("6105", 6105));
mMap.insert (std::pair<std::string, int>("6106", 6106));
mMap.insert (std::pair<std::string, int>("6107", 6107));
mMap.insert (std::pair<std::string, int>("6108", 6108));
mMap.insert (std::pair<std::string, int>("6109", 6109));
mMap.insert (std::pair<std::string, int>("6110", 6110));
mMap.insert (std::pair<std::string, int>("6111", 6111));
}
Note: the values above are for demonstration purposes and not what I am
actually using.
The g++ compilation time for this with no optimization is ~13 seconds, which is
surprising long.
$ time g++ -g -ftime-report test.cpp
Execution times (seconds)
garbage collection : 0.73 ( 6%) usr 0.00 ( 0%) sys 0.73 ( 6%)
wall 0 kB ( 0%) ggc
callgraph construction: 0.55 ( 5%) usr 0.04 ( 7%) sys 0.60 ( 5%)
wall 12476 kB ( 2%) ggc
callgraph optimization: 0.01 ( 0%) usr 0.00 ( 0%) sys 0.01 ( 0%)
wall 0 kB ( 0%) ggc
cfg cleanup : 0.41 ( 3%) usr 0.00 ( 0%) sys 0.41 ( 3%)
wall 0 kB ( 0%) ggc
trivially dead code : 0.09 ( 1%) usr 0.00 ( 0%) sys 0.08 ( 1%)
wall 0 kB ( 0%) ggc
life analysis : 0.61 ( 5%) usr 0.01 ( 2%) sys 0.62 ( 5%)
wall 16256 kB ( 2%) ggc
life info update : 0.29 ( 2%) usr 0.00 ( 0%) sys 0.29 ( 2%)
wall 3439 kB ( 0%) ggc
alias analysis : 0.20 ( 2%) usr 0.00 ( 0%) sys 0.20 ( 2%)
wall 4102 kB ( 1%) ggc
register scan : 0.07 ( 1%) usr 0.00 ( 0%) sys 0.07 ( 1%)
wall 0 kB ( 0%) ggc
rebuild jump labels : 0.11 ( 1%) usr 0.00 ( 0%) sys 0.10 ( 1%)
wall 0 kB ( 0%) ggc
preprocessing : 0.11 ( 1%) usr 0.07 (12%) sys 0.19 ( 2%)
wall 1452 kB ( 0%) ggc
parser : 0.77 ( 7%) usr 0.18 (31%) sys 0.86 ( 7%)
wall 123814 kB (18%) ggc
name lookup : 0.14 ( 1%) usr 0.10 (17%) sys 0.30 ( 2%)
wall 8390 kB ( 1%) ggc
inline heuristics : 0.01 ( 0%) usr 0.00 ( 0%) sys 0.01 ( 0%)
wall 0 kB ( 0%) ggc
integration : 0.01 ( 0%) usr 0.00 ( 0%) sys 0.01 ( 0%)
wall 0 kB ( 0%) ggc
tree gimplify : 0.23 ( 2%) usr 0.01 ( 2%) sys 0.25 ( 2%)
wall 17802 kB ( 3%) ggc
tree eh : 0.21 ( 2%) usr 0.03 ( 5%) sys 0.23 ( 2%)
wall 89644 kB (13%) ggc
tree CFG construction : 0.21 ( 2%) usr 0.02 ( 3%) sys 0.23 ( 2%)
wall 83144 kB (12%) ggc
tree CFG cleanup : 0.26 ( 2%) usr 0.00 ( 0%) sys 0.26 ( 2%)
wall 512 kB ( 0%) ggc
expand : 1.58 (13%) usr 0.03 ( 5%) sys 1.60 (13%)
wall 204964 kB (29%) ggc
varconst : 0.00 ( 0%) usr 0.00 ( 0%) sys 0.01 ( 0%)
wall 97 kB ( 0%) ggc
jump : 0.31 ( 3%) usr 0.01 ( 2%) sys 0.34 ( 3%)
wall 29427 kB ( 4%) ggc
branch prediction : 0.13 ( 1%) usr 0.00 ( 0%) sys 0.14 ( 1%)
wall 0 kB ( 0%) ggc
flow analysis : 0.09 ( 1%) usr 0.00 ( 0%) sys 0.10 ( 1%)
wall 0 kB ( 0%) ggc
mode switching : 0.01 ( 0%) usr 0.00 ( 0%) sys 0.01 ( 0%)
wall 0 kB ( 0%) ggc
local alloc : 0.94 ( 8%) usr 0.01 ( 2%) sys 0.95 ( 8%)
wall 4134 kB ( 1%) ggc
global alloc : 2.39 (20%) usr 0.05 ( 8%) sys 2.45 (20%)
wall 74298 kB (11%) ggc
flow 2 : 0.34 ( 3%) usr 0.00 ( 0%) sys 0.33 ( 3%)
wall 15547 kB ( 2%) ggc
final : 0.93 ( 8%) usr 0.03 ( 5%) sys 0.95 ( 8%)
wall 4141 kB ( 1%) ggc
symout : 0.01 ( 0%) usr 0.00 ( 0%) sys 0.01 ( 0%)
wall 1846 kB ( 0%) ggc
TOTAL : 11.75 0.59 12.35
697454 kB
real 0m13.691s
user 0m12.891s
sys 0m0.684s
If I add the -O1 optimization flag to the compiler, it takes an extreme amount
of time and also uses a lot of memory during compiling. It is still running
(after 36+ minutes) but here is the output from top so far:
PID USER PR NI VIRT SWAP RES CODE DATA SHR S %CPU %MEM TIME+
COMMAND
11174 me 25 0 4658m 90m 4.5g 6416 4.5g 10m R 100.0 12.6 36:00.14
/usr/libexec/gcc/x86_64-redhat-linux/4.1.2/cc1plus -quiet -D_GNU_SOURCE
test.cpp -quiet -dumpbase test.cpp -mtune=generic -auxbase test -g -O1
-ftime-report -o /tmp/ccgPeF5L.s
What is causing this to happen?
I cannot use C++ 11. I've checked gcc versions 4.1.2, 4.4.4 and 4.8.5.
I know I could just have a function that reads the values from a file at run
time and insert them into the map but I would like to understand the problem
first.
More information about the Gcc-bugs
mailing list