Re: Why is VC++ STL so slow?
MariuszK wrote:
Hello,
Could you write the simplest example when problem accure?
If problem accure only in map and set container I think that is
connected with container implementation.
Microsoft prefer implementation map with as hash_map (MFC CMap it is
hash_map). Generally hash_map is faster then normal map (finding time,
acces time etc.).
hash_map is a different type of map. It is nothing specific to
Microsoft. STL doesn't have a hash_map but there are several
open-source versions available, often provided as extensions to STL.
Using big O notation, hash_map is faster as the number of elements
tends to infinity, because insertion is constant time (i.e. it takes
the same amount of time regardless of the number of elements in the
collection). Constant time doesn't always mean faster than O( log N ).
Only as the size tends to infinity. For example, the constant time
could be 30. That means you'd need 2^30 elements (around 1 billion)
before hash_map became faster.
But adding element to hash_map is slower. (It is
connected with hashing algorithm if you add many elements hashing
algorithm is called many times). Therefore, If you add alements to
hash_map first you should initialize size of hash_map. Initialization
is very important for hash_map.
Indeed hash_map is less scalable as you have to determine in advance
the size of your hash_map as well as a good hashing algorithm which
will provide a uniform distribution without taking the "constant"
hashing-time too high, but we are getting a bit off-topic here.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]