c++ - unordered_map really slow even with cheap hash (profiled) -


i try profile cpu-intensive part of program.

it stunned me, unordered_map's iscontain, insert, , remove really slow.

here real example of result profiling:-

physic_object* cave = ... function argument ... if(cave->id==3){                            //< 0.1% simple int     int asdfdssd=0; } //"concaves" myencapsulatorof_unordered_map<physic_object*> (it field) //there 500-1000 elements in unordered_map. if (phy_concaves.iscontain(cave)) {         //0.8%  unordered_map "iscontain"      phy_concaves.remove_immediate(cave);    //4.9%  unordered_map "iscontain" + "erase"     cave->finalize_inverse();               //6.0%  lot of unordered_map function     delete cave;                            //0.7%  simple delete }else { } 

here cheap hash function.

//physic_object.h public:virtual long hqhashcode() const override final {     return id;      //id +1 every time when new physic_object create     //i have static int "id_runner" track. } 

from whole profile, unordered_map's operations gobbling 70%-80% of game.

question: unordered_map slow that, or there wrong code?
more specifically, common insertion/deletion cost around 40+ simple arithmetic operation?

here how create unordered_map, don't think there wrong, provided in case.

//myencapsulatorof_unordered_map<k> ,  k can pointer or value template<typename t2> static const     t2 * ptr(t2 const& obj) { return &obj; } //turn reference pointer! template<typename t2> static     t2 * ptr(t2 * obj) { return obj; } //obj pointer, return it! template< class t2>class structtptr1 {     public:     std::size_t operator()(t2 const& t) const{         std::size_t h1 = ptr(t)->hqhashcode();         return h1;     } }; template< class t2>class structtptr2 {     public: bool operator() (const t2 & t1, const t2&t2) const {         return t1 == t2;     } }; public:std::unordered_set<k, structtptr1<k>, structtptr2<k>>main; 

note ran in debug mode visual c++, release mode yields similar result.

why unordered_map hashing slow simple array hash seems related question, doesn't indicate/profile performance of unordered_map.

i don't think gcc either. therefore link may not relate. is gcc std::unordered_map implementation slow? if - why?