K
Krishanu Debnath
Hello,
I have a call to hash_map::clear() function which takes long time.
someClass::someFunction()
{
// typedef hash_map<name_id, uint> Mp;
// Mp p;
// assuming proper namespace, hash function for name_id obj.
p.clear();
}
Above p.clear() takes long time, profiling indicates 'number of bucket
of hash table is large'.
Now, just for sake of experiments, I replaced this 'clear' call with
swap. i.e.
someClass::someFunction()
{
// typedef hash_map<name_id, uint> Mp;
// Mp p;
// assuming proper namespace, hash function for name_is obj.
//p.clear();
Mp tmp;
p.swap(tmp);
}
Now runtime drops significantly, 10 fold less.
What's exactly cause this run time reduction?
Thanks,
Krishanu
I have a call to hash_map::clear() function which takes long time.
someClass::someFunction()
{
// typedef hash_map<name_id, uint> Mp;
// Mp p;
// assuming proper namespace, hash function for name_id obj.
p.clear();
}
Above p.clear() takes long time, profiling indicates 'number of bucket
of hash table is large'.
Now, just for sake of experiments, I replaced this 'clear' call with
swap. i.e.
someClass::someFunction()
{
// typedef hash_map<name_id, uint> Mp;
// Mp p;
// assuming proper namespace, hash function for name_is obj.
//p.clear();
Mp tmp;
p.swap(tmp);
}
Now runtime drops significantly, 10 fold less.
What's exactly cause this run time reduction?
Thanks,
Krishanu