Re: optimizing std::map or std::hash_map for speed
Costellj@gmail.com wrote:
Hello,
I am converting an app written in mfc to be cross platform. The
goal
is for the app to be as fast or faster than it's mfc's equivalent.
I
am doing some preliminary tests with std::map and std::hash_map
compared with CMap. I believe I am missing something in how I am
implementing the stl containers, or perhaps my test is bad. In
general this is my test:
get current time
for Cmap I call InitHash() with a prime number bigger than what I
need
for std::map, std::hash_map I use the get allocater to allocate the
space I need in advance
then I call a for loop and insert 2 million values
I then subtract the current time from the previous to get how many
seconds it takes
In my Cmap code this take between 8 and 9 seconds, but with each of
the stl it is well over 30 seconds.
I know that there must be an error in something I'm doing to get
this
drastic of differences. I just can't figure it out for the life of
me
Thanks in advance
Jon
Why are you testing insert specifically?
If that is the bulk of the work your program does, why not try a
std::vector and a final sort? If insert isn't the busiest part of your
program, why benchmark it?
Bo Persson