I am developing a latency sensitive application in C++. There's a module where I am using boost::unordered_map. I experienced too much latency while inserting first entry to the map, after that all the entries have decent insertion time.
If I use std::unordered_map instead of boost::unordered_map this behaviour does not occur. In this case, the first insertion also takes few hundred nano seconds(100~200).
Here are some time stats which I noticed: - 1st insertion in map : around 12 micro Sec(10 ~ 12 micro Sec) - After that almost all the insertions : 200 nano Sec(approx)
Here is the sample code for illustration:
struct timespec _timeSpec ;
long getTimerTime()
{
clock_gettime(CLOCK_REALTIME, &_timeSpec);
return ( 1000000000 * _timeSpec.tv_sec ) + _timeSpec.tv_nsec;
}
int main()
{
int i = 0;
boost::unordered_map < uint64_t , std::pair < uint64_t , bool > > _turnAroundTime ;
while( ++i != 10 )
{
uint64_t t1 = getTimerTime() ;
_turnAroundTime[i] = std::make_pair ( i, true );
uint64_t t2 = getTimerTime() ;
std::cout << "Latency : " << t2 - t1 << std::endl;
}
return 0 ;
}