http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57885

            Bug ID: 57885
           Summary: unordered_map find slower in 4.8.1 than 4.7.3 with
                    integer key
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jhand at austin dot rr.com

Created attachment 30499
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30499&action=edit
unordered_map.cpp

I have been looking at performance of std::unordered_map versus
tr1::unordered_map using gcc-4.6.3, gcc-4.7.3, and gcc-4.8.1. I am mostly
interested in the performance of find(), although insertion performance is
important too.

I am attaching a simple program that creates a vector of 100,000 integers. It
calls a function that measures the time to insert the vector into an
unordered_map of integers to integers. It does this in a loop five times,
recording the amount spent each time, and clearing the unordered_map at the end
of the loop except the final time through the loop. The time to clear the map
is not measured.

Then within a loop of 5 times, it performs find() on the unordered map using
the original vector of integers. It measures the time spent looking up all of
the integers in the vector 5 times.

On gcc-4.6.3, I get the following output (the numbers are microseconds):
 Container:std::unordered_map<int,int>  Key:int
 Insertion: 10458 4885 4874 4892 4871  min=4871 max=10458
 Lookup:    11609 11613 11597 11611 11594  min=11594 max=11613

 Container:std::tr1::unordered_map<int,int>  Key:int
 Insertion: 12399 4963 4948 4949 4961  min=4948 max=12399
 Lookup:    11580 11573 11562 11559 11570  min=11559 max=11580

On gcc-4.7.3, I get the following output:
 Container:std::unordered_map<int,int>  Key:int
 Insertion: 14454 16288 16499 15830 15753  min=14454 max=16499
 Lookup:    12229 12208 12204 12201 12200  min=12200 max=12229

 Container:std::tr1::unordered_map<int,int>  Key:int
 Insertion: 9926 4978 5000 4972 4971  min=4971 max=9926
 Lookup:    11667 11636 11646 11636 11652  min=11636 max=11667

On gcc-4.8.1, I get the following output:
 Container:std::unordered_map<int,int>  Key:int
 Insertion: 13234 7441 7519 7546 7569  min=7441 max=13234
 Lookup:    14812 14823 14846 14810 14805  min=14805 max=14846

 Container:std::tr1::unordered_map<int,int>  Key:int
 Insertion: 12450 5228 5197 5186 5249  min=5186 max=12450
 Lookup:    11579 11530 11592 11535 11529  min=11529 max=11592

It looks like the tr1::unordered_map implementation performs approximately the
same across compilers.

The std::unordered_map::find() implementation slows down by approximately 5.2%
in gcc-4.7.3 compared to gcc-4.6.3. It slows down by about 27.7% in gcc-4.8.1
compared to gcc-4.6.1. The insertion performance is about 52.7% worse in
gcc-4.8.1 compared to gcc-4.6.1.

The code was compiled with the following:

g++ -std=c++0x -DNDEBUG -O3 -o unordered_map unordered_map.cpp

This is on Linux x86_64 with Intel Xeon X5570 @ 2.93GHz.

I have seen this performance degradation with some of my user defined classes,
but I thought that an integer key best shows the issue.

Reply via email to