http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54075
Bug #: 54075 Summary: [4.7.1] unordered_map 3x slower than 4.6.2 Classification: Unclassified Product: gcc Version: 4.7.1 Status: UNCONFIRMED Severity: critical Priority: P3 Component: libstdc++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: likan_999.stud...@sina.com The following piece of code shows 3x performance regression from 4.6.2 to 4.7.1. The reason should come from the change in libstdc++. The code is compiled with -O2 -std=c++0x. -O3 doesn't make much difference; with or without the call to reserve doesn't make much difference. The attachment contains profiling using google-perftool. Looks like the major cost comes from the rehashing. Does anyone aware of the issue, or I am the first one to report this? #include <unordered_map> using namespace std; int main() { const int N = 10000000; unordered_map<int, int> m; m.reserve(2 * N); for (int i = 0; i < N; i++) { m[i] = i; } } Timing: [hidden]$ time ./a-4.6.2.out real 0m1.029s user 0m0.787s sys 0m0.239s [hidden]$ time ./a-4.7.1.out real 0m3.364s user 0m2.596s sys 0m0.761s