Re: stdext::hashmap and std::map are different perfermance in Multi Threaded Base
On Wed, 1 Jul 2009 20:23:58 CST, metdoloca@naver.com wrote:
in <multi threaded> programming( maybe threadcount is 100 )
1. map
std::map< long,DATA > testMap[100];
LockObject lock[100];
ThreadProc()
{
long lSerial = rand();
long lHashSerial = lSerial%100;
DATA sData;
// LockStart
{
LockObejct lock( lock[100] );
testMap[lHashSerial] = sData
}
// LockEnd
}
Example 1 should not even compile ... you are trying to assign a DATA
object to a map instead of inserting the data object into the map. You
are also synchronizing all threads on a single lock which is probably
not what you intended given that you have 100 maps.
I don't know what this LockObject is that you are using, but modulo
correct use of it, the code for this example should probably be
something like:
LockObject lock( lock[lHashSerial] )
testMap[lHashSerial][lSerial] = sData;
or
lock[lHashSerial].Lock();
testMap[lHashSerial][lSerial] = sData;
lock[lHashSerial].Unlock();
2. hashmap
stdext::hashmap< long, DATA > testHashMap;
LockObject lock;
ThreadProc()
{
long lSerial = rand();
DATA sData;
// LockStart
{
LockObejct lock( lock );
testHashMap[lSerial] = sData
}
// LockEnd
}
which is more perfermance?
1 or 2
A hash_map is generally much faster than a map, although it _could_
potentially be slower depending on the complexity of the optional
custom hash and comparison functions (your hash_map example uses the
default versions).
However, I'm not sure you really know what you are asking because your
examples are not functionally equivalent. Your map code uses multiple
maps whereas your hash_map code uses a single map. Are you asking
about the relative performance of std::map vs stdext::hash_map or the
relative performance of using a single map vs multiple maps?
George
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]